好的,简而言之,我需要做的是在加载时自动将一组排序条件和数据过滤器应用于jqGrid.目的是用户将从大约10个预填充过滤器开始,然后,如果他们选择,他们可以改变那些过滤器或他们认为合适的排序.
到目前为止,有很多谷歌,试验和错误和汗水,我有以下工作:
- >我可以在会话cookie中加载/保存排序列和排序顺序.
- >我可以使用预定义的搜索过滤器加载搜索对话框.网格加载后,我可以打开模态对话框并查看正确的过滤器,如果单击"查找",相应的数据将发布到服务器,并将正确的结果返回到屏幕.
我认为现在正在咬我的东西是容易的部分,但它逃脱了我.我似乎无法做以下任何一种情况:
(A)理想的情况是,如果我可以将这些过滤器附加到网格并且它在初始加载之前发布数据,那么只有一次到服务器的行程.
(B)可行的解决方案虽然不太理想,但是网格首先加载未过滤数据的第一页,然后应用过滤器并重新查询服务器以获取过滤后的数据.
由于今天我可以手动点击"查找"按钮并且它有效,我认为"B"将是一个很好的下一步.所以,在我的gridComplete函数中,我有以下代码:
$('#AccountGrid').clearFilter({gridName:'AccountGrid', pagerName:'AccountPager'});
$('#AccountGrid').addFilter({gridName:'AccountGrid', field:'AccountID', data:1, op:'ne'});
$('#AccountGrid').addFilter({gridName:'AccountGrid', field:'AccountID', data:3, op:'ne'});
// $('#fbox_AccountGrid').searchFilter().search();
// $('#fbox_AccountGrid .ui-search').click();
$('#AccountGrid').trigger('reloadGrid');
NOTE: "clearFilter" and "addFilter" are extension functions I have added to jqGrid to simplify adding and removing filters on the grid. They work exactly as desired at this point.
As you can see with those last three lines of code, I have tried using the built-in function, as well as going after the find …Run Code Online (Sandbox Code Playgroud)