Trirand 的 jqGrid 的 gridComplete 事件的计时

发布于 2024-12-06 02:09:57 字数 1449 浏览 1 评论 0原文

我不相信 gridComplete 事件在“所有数据加载到网格中并且所有其他进程都完成之后”运行,如 文档

我有一个正在正确加载的网格。在 gidComplete 事件中,我会触发一些过滤方法(.extend 和 .setGridParam),以便在加载网格后立即应用过滤器。但是,尽管我的自定义函数正在触发(通过控制台看到),但过滤器并未被应用。如果我使用 setTimeout 将执行延迟一秒(左右),那么实际上会应用过滤器。所以在我看来 gridComplete 触发得太早了。

顺便说一句,过滤器函数(称为 setGridFilter())也会在绑定到选择菜单(用户可以从预设过滤器选项中进行选择)的 onchange 事件中触发。这非常有效。只是该函数的 gridComplete 调用失败了。

$("#list3").jqGrid({
   url: 'blah.php',
   colNames: ['blah1','blah2','etc.','PresentationTemplateID'],
   colModel: [name: 'blah1', index: 'blah1'],
       [name: 'blah2', index: 'blah2'],
       [name: 'etc.', index: 'etc.'],
       [name: 'PresentationTemplateID', index: 'PresentationTemplateID', hidden:true]
   viewRecords:true,
   loadonce: true,
   pager: '#pager3',
   search:true,
   gridComplete: function(){
       //var t = setTimeout('setGridFilter()',1000);   //this works, for some reason
       setGridFilter();  //this does not
   }
});

function setGridFilter() {
   var postdata = $("#list3").jqGrid('getGridParam','postData');
   var text = $("#ddlGridFilterMenu").val(), f;
   $.extend(postdata,{filters:'',searchField: 'PresentationTemplateID', searchOper: 'eq', searchString: text});
   $("#list3").jqGrid('setGridParam', { search: text.length>0, postData: postdata });
   $("#list3").trigger("reloadGrid",[{page:1}]);
}

I'm not convinced that the gridComplete event runs "after all the data is loaded into the grid and all other processes are complete," as specified in the documentation.

I've got a grid that is loading correctly. In the gidComplete event, I'm triggering some filtering methods (.extend and .setGridParam) to apply a filter as soon as the grid is loaded. However, although my custom function is firing (seen through console), the filter is not being applied. If I use the setTimeout to delay the execution by a second (or so), then the filter is, in fact, applied. So it seems to me that the gridComplete is firing too early.

Incidentally, the filter function (called setGridFilter()) also fires in an onchange event bound to a select menu (where the user can choose from pre-set filter options). This works perfectly. It's just the gridComplete invocation of this function that is failing.

$("#list3").jqGrid({
   url: 'blah.php',
   colNames: ['blah1','blah2','etc.','PresentationTemplateID'],
   colModel: [name: 'blah1', index: 'blah1'],
       [name: 'blah2', index: 'blah2'],
       [name: 'etc.', index: 'etc.'],
       [name: 'PresentationTemplateID', index: 'PresentationTemplateID', hidden:true]
   viewRecords:true,
   loadonce: true,
   pager: '#pager3',
   search:true,
   gridComplete: function(){
       //var t = setTimeout('setGridFilter()',1000);   //this works, for some reason
       setGridFilter();  //this does not
   }
});

function setGridFilter() {
   var postdata = $("#list3").jqGrid('getGridParam','postData');
   var text = $("#ddlGridFilterMenu").val(), f;
   $.extend(postdata,{filters:'',searchField: 'PresentationTemplateID', searchOper: 'eq', searchString: text});
   $("#list3").jqGrid('setGridParam', { search: text.length>0, postData: postdata });
   $("#list3").trigger("reloadGrid",[{page:1}]);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思慕 2024-12-13 02:09:57

尝试使用 loadComplete 代替。

Try using loadComplete instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文