Jqgrid save filter on reload

This question has been so many, so please forgive me again.

I have a grid loaded from a url.

I am using loadonce: true

I am using filtertoolbar:

$("#status").jqGrid('filterToolbar', { stringResult:true, searchOnEnter:false, autosearch: true, defaultSearch: "cn" });

      

I have a search dropdown from which I can select what I am looking for. Works great.

I have a navbutton that I click to initiate a restart every 30 seconds. Works great.

$("#status").jqGrid('navButtonAdd','#statuspager', { caption: '', buttonicon: 'ui-icon-play', onClickButton: function ()
{
stint = setInterval (function() {
      postfilt = $("#status").jqGrid('getGridParam', 'postData').filter;

      $("#status").jqGrid('setGridParam',{
             url: './ar_status.cgi?systemtype=' + systype,
             datatype: "json",
             postData: postfilt,
             search: true,
             loadtext: "Refreshing grid...",
             loadonce: true,
             loadui: "block"
      });
      $("#status").jqGrid().trigger("reloadGrid");
}, 30000);
},
title: 'Start Auto Refresh (every 30 sec.)'
});

      

Using google chrome I can see that the filters that were specified are being sent to the server:

systemtype:production
_search:true
nd:1358887757603
rows:1000
page:1
sidx:system
sord:asc
totalrows:700
filters:{"groupOp":"AND","rules":[{"field":"system","op":"eq","data":"ATTDA02"}]}

      

I can change the filter between reloads and see new ones, even multiple filters:

systemtype:production
_search:true
nd:1358887847592
rows:1000
page:1
sidx:system
sord:asc
totalrows:700
filters:{"groupOp":"AND","rules":[{"field":"system","op":"eq","data":"ATTDA02"},{"field":"dow","op":"cn","data":"MO"}]}

      

I am using multipleSearch: true for bootstrapping. I'm pretty sure saved across reboot

In the grid, filtertoolbar retains the filter criteria, both text and selects, but when the grid reloads, the filters are ignored and the entire dataset is duplicated in the grid.

I've tried many examples posted here on SO. I tried adding [{current: true}] to the reloadGrid call - no difference. I cannot save and apply filters on reload.

I would like reload to always return the full dataset from the server (which happens very well) and allows the current filter settings to control what is displayed after a reboot. I don't want to use postdata to create a new SQL select statement - server side filtering, because at any time the user might need to press the pause button, select a new filter, and view something else from the entire dataset without reloading again.

$("#status").jqGrid('navButtonAdd','#statuspager', { caption: '', buttonicon: 'ui-icon-pause', onClickButton: function ()
{
   clearInterval(stint);
},
title: 'End Auto Refresh'
});

      

How can this be done without using cookies, as I saw in one post?

I could try using jqGridExport'ing for the postfilt var and then jqGridImport'ing, but was hoping for a more direct approach. I'm not even sure if it helps as I already have everything I need right here in the grid via postData.

As a side note, in my setGridParam above, the loaded text I specify is never displayed. Instead, "Loading ..." is displayed by default. All other parameters work.

Thanks a lot in advance, Mike

Decision. Full loadComplete to preserve filters, sort index and sort order after reloading [json] from the server:

                    loadComplete: function() {
                            var $this = $(this);
                            postfilt = $this.jqGrid('getGridParam','postData').filters;
                            postsord = $this.jqGrid('getGridParam','postData').sord;
                            postsort = $this.jqGrid('getGridParam','postData').sidx;

                            if ($this.jqGrid("getGridParam", "datatype") === "json") {
                                    setTimeout(function () {
                                            $this.jqGrid("setGridParam", {
                                                    datatype: "local",
                                                    postData: {filters: postfilt, sord: postsord, sidx: postsort},
                                                    search: true
                                            });

                                            $this.trigger("reloadGrid");
                                    }, 50);
                            }
                    }

      

+3


source to share


2 answers


I'm not sure, but I suppose that mixing postData.filters

and postData

and using filter

instead of filters might be the source of your first problem . '' You're using

postfilt = $("#status").jqGrid('getGridParam', 'postData').filter;

      



to get the property filter

instead filters

. You get the meaning undefined

. Thus, the setting postData

- postfilt

does not mean anything.

The next problem is that the server response contains unfiltered data. To force filtering data locally, you must reload the mesh once after the download from the server is complete. You can do it internally loadComplete

. This is where you can set postData.filter

as needed, set search: true

and fire the reloadGrid event. It is important to do this once without recursion, and you should not set datatype

back "json"

in this case. datatype

will be changed to "local"

and end of download from server if option is used loadonce: true

. If you want to apply filtering locally, you need to reload the mesh once with the parameters datatype: "local", search: true

and postData

havingfilters

specifying the filter to apply. See Code or another that does other things, but the code you need will be very close.

+1


source


Many thanks!!!!

I added a bit of your solution to keep the page number:



                loadComplete: function () {
                var $this = $(this);
                var postfilt = $this.jqGrid('getGridParam', 'postData').filters;
                var postsord = $this.jqGrid('getGridParam', 'postData').sord;
                var postsort = $this.jqGrid('getGridParam', 'postData').sidx;
                var postpage = $this.jqGrid('getGridParam', 'postData').page;

                if ($this.jqGrid("getGridParam", "datatype") === "json") {
                    setTimeout(function () {
                        $this.jqGrid("setGridParam", {
                            datatype: "local",
                            postData: { filters: postfilt, sord: postsord, sidx: postsort },
                            search: true
                        });
                        $this.trigger("reloadGrid", [{ page: postpage}]);
                    }, 25);
                }
            }

      

+3


source







All Articles