jqgrid保留过滤器重新加载 [英] jqgrid retain filter on reload

查看:205
本文介绍了jqgrid保留过滤器重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经很多了,请原谅我再问一次。



我有一个从网址加载的网格。

我使用loadonce:true

我使用filtertoolbar:
$ b $ j $ Grid $(filterToolbar,{stringResult:true,searchOnEnter:false,autosearch:true,defaultSearch:cn});} $(#status

我有一个下拉搜索列表,我可以从中选择要查找的内容。很好。



我有一个navbutton,我点击每30秒启动一次重新加载。
$ b

  $(#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,
搜索:true,
loadtext:刷新网格...,
loadonce:true ,
loadui:block
});
$(#status)。jqGrid()。trigger(reloadGrid);
},30000);
},
title:'开始自动刷新(每30秒)'
});

使用google chrome,我可以看到指定的过滤器发布到服务器:


$ b $ pre $系统类型:生产$ b $ __search:true
nd:1358887757603
rows:1000
page: 1
sidx:system
sord:asc
totalrows:700
filters:{groupOp:AND,rules:[{field:system ,op:eq,data:ATTDA02}]}

更改重新加载之间的过滤器,并看到新的,甚至多个过滤器:

  systemtype:production 
_search:true
nd:1358887847592
rows:1000
page:1
sidx:system
sord:asc
totalrows:700
filters:{groupOp : AND, 规则:[{ 字段: 系统, 运算: 当量, 数据: ATTDA02},{ 场: 道氏, 运算:数据:MO}]}

我正在使用multipleSearch:true初始负载。我很确定这是保留在重新加载



在网格上,filtertoolbar保留我的过滤条件,包括文本和选择,但是当网格重新加载时,过滤器被忽略并将整个数据集显示在网格中。

我已经尝试了很多在这里发布的示例。我尝试添加[{current:true}]到reloadGrid调用 - 没有什么区别。我似乎无法保留和应用过滤器的重新加载。

我想重新加载总是从服务器返回完整的数据集(这很好),并允许当前的过滤器设置来控制重新加载后显示的内容。我不想使用postdata来构建一个新的SQL select语句 - 服务器端过滤,因为用户可能随时想要单击暂停按钮,选择一个新的过滤器并从整个数据集中查看其他内容,而无需另外重新加载。

  $(#status)。jqGrid('navButtonAdd','#statuspager',{caption:'',buttonicon :'ui-icon-pause',onClickButton:function()
{
clearInterval(stint);
},
标题:'结束自动刷新'
} );

如何在不使用cookies的情况下做到这一点,就像我在一篇文章中看到的那样?

我可以尝试使用jqGrid导出postfilt var,然后jqGridImport'ing它但希望有一个更直接的方法。我甚至不确定这会有帮助,因为我已经有了我需要的所有东西,通过postData在网格中。



另外,在上面的setGridParam中,我指定的loadtext从不显示。而是显示默认的正在加载...。所有其他的参数正在工作。



非常感谢提前,
Mike



解决方案。完整的loadComplete保留过滤器,在从服务器重新加载[json]之后对索引和排序顺序进行排序:

  loadComplete:function ){
var $ this = $(this);
postfilt = $ this.jqGrid('getGridParam','postData')。
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);



$ div $解析方案

我不知道,但我想你的第一个问题的起源可能是混合 postData.filters postData 和用法过滤器属性而不是过滤器``。您可以使用

  postfilt = $(#status)。 

得到过滤器属性而不是过滤。你得到 undefined 值。因此,设置 postData postfilt 就意味着什么。

接下来的问题是服务器响应包含未过滤的数据。要强制在本地过滤数据,您必须在从服务器加载完成后重新加载一次网格。你可以在 loadComplete 中做到这一点。完全可以在这里设置 postData.filter ,如果需要,设置 search:true 并触发reloadGrid事件。 一次没有递归,并且您不能将数据类型设置回json在这种情况下数据类型将被改为local,并且在使用 loadonce:true 选项。如果你想在本地应用过滤,你必须使用数据类型:local,搜索:true postData 具有过滤器指定需要应用的过滤器。请参阅答案另一个,这样做的另一件事,但你需要的代码将非常接近。


This question has been as a lot so please forgive me asking again.

I have a grid loaded from a url.

I use loadonce: true

I use filtertoolbar:

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

I have a dropdown search list from which I can select what I'm looking for. Works great.

I have a navbutton I click to initiate a reload 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 the filters that were specified being posted 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 the new, 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 on the initial load. I'm pretty sure that's retained on reload

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

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

I would like the reload to always return the full dataset from the server (which happens fine), and allow the current filter settings to control what is shown after the reload. I do not want to use the postdata to build a new SQL select statement - server side filtering, because at any time the user may want to click the pause button, select a new filter and view something else from the entire dataset without another reload.

$("#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 the postfilt var, and then jqGridImport'ing it but was hoping for a more direct approach. I'm not even sure this would help since I already have everything I need right here in the grid via postData.

As a side note, in my setGridParam above, the loadtext I specify is never displayed. Instead, the default "Loading..." is displayed. All of the other parameters are working.

Many thanks in advance, Mike

Solution. The complete loadComplete to retain filters, sort index and sort order after a [json] reload 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);
                            }
                    }

解决方案

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.

这篇关于jqgrid保留过滤器重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆