Author Topic: How to load the data from ajax to select tag inside the grid column  (Read 3256 times)

bsolteam

  • Pro Deluxe
  • Full Member
  • *
  • Posts: 107
    • View Profile
Hi paramquery team,

               I have a colmodel which is having the select tag. I want load the options for the select tag by making ajax call and get the data. I am getting the data in response, but that response data i have to display like option for select tag.So can u please give some suggestion for my problem.

Here is my code.
                          var colM = [  {
                  title : "Event",
                  width : '25%',
                  align : "center",
                  dataIndx : "eventType",
                  editable : false,
                  editor : {
                           type : 'select',
                           cls: "eventlist",
                                     options : function(ui)
                                                                                      {
                                    var opts = [];
                                 var options = ui.column.editor.options;
                                  cellData = ui.cellData;
                                    
                                             $.ajax ({
                                     type : 'GET',
                                    url : "getEventType",
                                    success : function(response) {
                                       
                                       alert(response);
                                       var cjson = eval('(' + response
                                             + ')');

                                       for (var i = 0; i < cjson.length; ++i) {
                                          
                                          opts.push(cjson.eventDesc);
                                       }
                                       
                                         for (var i = 0; i < cjson.length; i++) {
                                                                var option = opts;
                                                                if (option[cellData]) {
                                                                 return option[cellData];
                                                             }
                                                          }
                                       
                                    },
                                    error : function(e) {
                                       alert(e);
                                    },
                                   });
                                 
                             alert(opts);
                              },
                                                    },
                                 }]

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: How to load the data from ajax to select tag inside the grid column
« Reply #1 on: August 11, 2014, 11:17:13 am »
If the options in your select list are static then you could load them in create event of the grid and assign them to column.editor.options

If the options vary and you want to load them at every time of creation of select list, then you should make a synchronous ajax call by adding the below property in your $.ajax method

Code: [Select]
async: false
« Last Edit: August 11, 2014, 11:53:40 am by paramquery »