jqgrid retain filter on reload

时间秒杀一切 提交于 2019-11-29 08:04:47
Oleg

I am not sure, but I suppose that the origin of your first problem could be mixing postData.filters and postData and usage filter property instead of filters``. You use

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

to get filter property instead of filters. You get undefined value. So the setting postData to postfilt means nothing.

The next problem is that the server response contains non-filtered data. To force filtering the data locally you have to reload the grid once after the loading from the server have finished. You can do this inside of loadComplete. Exactly here you can set postData.filter if required, set search: true and trigger reloadGrid event. It's important only to do this once to have no recursion and you must don't set datatype back to "json" in the case. The datatype will be changed to "local" and the end of loading from the server in case of usage loadonce: true option. If you want apply filtering locally you have to reload grid once with options datatype: "local", search: true and postData having filters specifying the filter which need by applied. See the code from the answer or another one which do another things, but the code which you need will be very close.

Thanks very much!!!!

I only added a bit to your solution to retain the page number as well:

                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);
                }
            }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!