Author Topic: array for options for filter  (Read 3123 times)

angelahlp

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
array for options for filter
« on: February 20, 2014, 08:54:15 am »
I am creating an array that I am using to populate drop down boxes inside the grid. I would like to use this same array to populate the drop down box for a column filter but cannot figure out how to format the array so that it is accepted by the "options" in the filter under colModel. Code examples are below. Any help is appreciated!!!

  var arrSimulatorGroups = [];
    $.ajax({ url: "/cfc/form.cfc?method=getSims&randomval=" + noCache, success: function (response) { arrSims = response.split(","); } });


        colModel: [...

         { title: "Sim", width: 150, dataIndx: 'sim', render: filterRender,
               editor: {
                   type: function (ui)
               {dropDownEditor(ui,arrSims)}
               },
            filter: { type: 'select',
               options: arrSims, <----------------------------this is where the array is not being accepted-------------------
               condition: 'equal',
               listeners: [{ change: function (evt, ui) {
                  filter("sim, $(this).val());
                  }
               }]
            }
          },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: array for options for filter
« Reply #1 on: February 20, 2014, 10:57:27 am »
Quote
var arrSimulatorGroups = []; //<- it should be arrSims??
    $.ajax({ url: "/cfc/form.cfc?method=getSims&randomval=" + noCache, success: function (response) { arrSims = response.split(","); } });

You make an async Ajax call and arrSims is available after it has been already been assigned (empty value) to the filter. You should assign the arrSims to filter within the success callback

Code: [Select]
success: function (response)
{
  arrSims = response.split(",");
  var column = $grid.pqGrid("getColumn", {dataIndx: 'sim'});
  column.filter.options = arrSims;
  $grid.pqGrid("refresh");
}
« Last Edit: February 20, 2014, 10:59:23 am by paramquery »