Author Topic: JSON select takes too long and focus jumps on tabbing  (Read 3340 times)

suvalkon

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 10
    • View Profile
JSON select takes too long and focus jumps on tabbing
« on: September 09, 2014, 03:09:07 am »
Hi

MY PayPAL transaction id xxxx180S (Mainstream NZ Ltd).

When you tab in inline editing and you have a select and you don't wait until it is visible the focus goes out of the grid.
The following code is the JSON function on editor init: selectTypes.

// ---------------------
   // Select Freight Types
   // ---------------------
   var selectTypes = function (ui) {
      $inp = ui.$cell.find("select");
      $grid = $(this);
      //alert(ui.cellData);
      //console.log($inp);
      //var dataIndx = ui.dataIndx;
      url = "https://rest.mainstream.co.nz:9191/MAINTEST/subroutine/WEBUSRUPD";
      var params = new Object();
      params.user = user;
      params.userdetin = "0";
      params.mode = "ENQ";
      $.support.cors = true;
      $.ajax({
         type: "POST",
         dataType: 'json',
         data: JSON.stringify(params),
         url: url,
         contentType: "application/json; charset=utf-8",
         beforeSend: function (xhr) {  //MNS
               xhr.setRequestHeader("Authorization",
                        "Basic d2VidXNlcjptNCR0M3I=");
                }, //MNS
         success: function (pdata) {
            var s1 = pdata.msg.msgSeverity,
               s2 = pdata.msg.msgCust,
               s3 = pdata.msg.msgMain;
            if (s1 == "F") {
               alert(s3);
            } else {
               console.log(s1 + " " + s3);
            }
            var seldet = [];
            var seldef = "";
            $(pdata.svs.jobt).each(function (val) {
               var opt = $('<option />');
               if (this.jobTyp == ui.cellData) {
                  // this is the default option so set the 'selected' attribute
                  opt.attr('value', this.jobTyp).text(this.jobDesc);
                  opt.attr('selected', 'selected');
               }
               else {
                  opt.attr('value', this.jobTyp).text(this.jobDesc);
               }
               $inp.append(opt);
            });
         },
         error: function () {
         // constitutes some error from the Web Service
            console.log("WEBUSRUPD failed");
         }
      });
   };
« Last Edit: September 09, 2014, 08:55:07 am by paramquery »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: JSON select takes too long and focus jumps on tabbing
« Reply #1 on: September 09, 2014, 11:45:38 am »
If the options in select list are static, you may fetch them from server during initialization/ creation of the grid and reuse them.

But if the options vary for different cells in the same column, you have to wait for the options to return from server by making synchronous ajax request.

async: false
« Last Edit: September 09, 2014, 11:58:41 am by paramquery »

suvalkon

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: JSON select takes too long and focus jumps on tabbing
« Reply #2 on: September 09, 2014, 02:18:32 pm »
Can you be a bit more specific with a bit of code on what you mean by initialisation of the grid?

Which event?

Can you give me an example of how to reuse the data since it is coming from a JSON query?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: JSON select takes too long and focus jumps on tabbing
« Reply #3 on: September 09, 2014, 05:52:01 pm »
create event is fired once during creation of grid.

http://paramquery.com/pro/api#event-create

you may fetch options from the server in this event and assign it to column.editor.options in $.ajax success callback.

http://paramquery.com/pro/api#option-column-editor