Author Topic: Filter not working after Ajax Call  (Read 2521 times)

svk123

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 9
    • View Profile
Filter not working after Ajax Call
« on: December 22, 2015, 12:54:34 pm »
Hello,

I trying to use Header filtering. If I bring the data using spaghetti code and insert it into pqgrid at time of grid declaration, the filter works fine. However, if I bring the data using an Ajax call and insert it into the datamodel later, the filter is not working. In this case data is set as []; at time of grid declaration. Am I missing any refresh for the filter? I am using 2.0.4 version.

Please find below my code of the ajax call:
Code: [Select]
        $.ajax({
            type: "POST",
            url: "F1910.aspx/bindGrid1",
            data: '{"apprlvl":"' + appr + '"}',
            processData: false,
            contentType: "application/json",
            dataType: "json",
            async: true,
            cache: false,
            success: function (msg) {
                var obj = eval(msg.d);
                $("#grid_json").pqGrid("option", "dataModel", { data: obj, sorting: "local",sortIndx: ["uckalerts","pono", "posrno"], sortDir: ["down","up","up"]});
               
                $("#grid_json").pqGrid("refreshDataAndView");
            },
            error: function (x, e) {
                alert("The call to the server side failed. " + x.responseText);
            }

        });

Thanks,
SVK

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Filter not working after Ajax Call
« Reply #1 on: December 23, 2015, 12:14:49 pm »
$("#grid_json").pqGrid("option", "dataModel", { ....}); overrides all the properties ( including default ones ) of dataModel which is problematic if you skip any dataModel property.

As an alternative please declare the static properties like dataModel.sorting = "local" during grid initialization and try to update the dataModel properties individually in the success callback

e.g.,

$("#grid_json").pqGrid("option", "dataModel.data", data );

$("#grid_json").pqGrid("option", "dataModel.sortIndx", .... );

and so on.
« Last Edit: December 23, 2015, 01:02:38 pm by paramquery »