jqGrid - 自定义过滤有效,但在模式窗口中重新打开网格后无效

发布于 2025-01-05 08:09:20 字数 1387 浏览 0 评论 0原文

我有一个自定义过滤功能,它传入自定义 url 并通过以下方式重新加载网格数据:

function filter_grid(filter) {
    grid = $(filter).parents('.ui-jqgrid-view').find('.grid');
    /* build the url in here*/
    $(grid).setGridParam({loadonce:false, datatype:'json'});
    jQuery(grid).setGridParam({url:myurl}).trigger("reloadGrid");
    $(grid).setGridParam({loadonce:true});
}

这工作正常并按预期过滤数据。但是,我允许用户在模式窗口中打开网格,这在您第一次打开模式窗口时也将起作用但是如果您随后关闭窗口并重新打开它...过滤失败。我在控制台中没有看到任何错误...只是重新加载似乎永远不会发生。有什么建议吗?


说明

简而言之,每个网格都有一个选择菜单。您可以在该菜单中选择一个选项,它将通过 filter_grid 函数使用过滤后的数据重新加载网格。它通过使用新的 url 重新加载网格来重新加载,该新 url 会传入一些参数来过滤数据。

在 gridComplete 事件中,我将一个选择输入元素(稍后填充)附加到页面上的每个网格。每个都有一个“过滤器”类:

$("#grid1 .ui-jqgrid-titlebar:eq(1)").append("<select id='pdd_user' name='filter_user' class='category_select filter'><option value=''>All</option></select>")

我监视过滤器类上的点击:

$('.filter').live('change', function() {
        filter_grid(this);
    });

它调用 filter_grid 函数(我在问题的第一次编辑中包含在上面的函数),如您所见,这就是用过滤后的数据重新填充网格的方法:

jQuery(grid).setGridParam({url:myurl}).trigger("reloadGrid"); 

我将其设置为 loadonce:false,因为网格在最初创建时设置为 loadonce:true (出于本地排序目的),所以我将其设置回 loadonce:false,重新加载网格新的 url 和 params,然后将其设置回 loadonce:true 以再次启用本地排序。

I have a custom filtering function, it passes in a custom url and reloads grid data via:

function filter_grid(filter) {
    grid = $(filter).parents('.ui-jqgrid-view').find('.grid');
    /* build the url in here*/
    $(grid).setGridParam({loadonce:false, datatype:'json'});
    jQuery(grid).setGridParam({url:myurl}).trigger("reloadGrid");
    $(grid).setGridParam({loadonce:true});
}

This works fine and filters data as expected. However, I allow the user to open the grid in a modal window and this will also work the first time you open the modal window but if you then close the window and reopen it... filtering fails. I see no errors in console... just the reload never seems to happen. Any suggestions?


Clarification

In a nutshell there is a select menu attached to each grid. You can select an option in that menu and it will reload the grid with the filtered data via the filter_grid function. It reloads by reloading the grid with a new url that passes in some parameters to filter the data.

In the gridComplete event I append a select input element (which I populate later) to each grid on the page. Each one has a class of "filter":

$("#grid1 .ui-jqgrid-titlebar:eq(1)").append("<select id='pdd_user' name='filter_user' class='category_select filter'><option value=''>All</option></select>")

I watch for clicks on the filter class:

$('.filter').live('change', function() {
        filter_grid(this);
    });

That calls the filter_grid function (the one I included above with the first edit of my question), as you can see, and that is what repopulates the grid with the filtered data:

jQuery(grid).setGridParam({url:myurl}).trigger("reloadGrid"); 

I set it to loadonce:false because the grid was set to loadonce:true when it was initially created (for local sorting purposes) so I set it back to loadonce:false, reload the grid with the new url and params, and then set it back to loadonce:true in order to enable local sorting again.

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

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

发布评论

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

评论(1

挽你眉间 2025-01-12 08:09:20

我不完全理解你的问题,但我希望我能帮助你找出代码中的问题。我认为您应该删除对 j​​qGrid 的 loadonce 选项的任何操作。这是不必要的而且危险的。要使用服务器数据重新加载网格,您只需将 datatype 设置为 'json' 并使用 .trigger("reloadGrid", [{page: 1、当前:true}]);(有关详细信息,请参阅此处)。如果重新加载后在网格中找到所选行,则参数 current: true 有助于保留所选行。如果您使用数据分页,参数 page: 1 会有所帮助。例如,如果用户选择第二页,然后启动 reloadGrid,它将请求服务器加载过滤结果的第二页。。因此寻呼机中可以有空网格和页码 2。在这种情况下,使用 setGridParam 或使用上述 reloadGrid 参数将页码重置为 1 会有所帮助。

loadonce: false 设置的问题可能是在设置 loadonce: true 之前处理网格的重新加载。在这种情况下,网格中不会填充任何本地数据。因此应该永久设置选项loadonce: true

如果您使用带有本地数据排序的服务器端分页,我建议您另外阅读此答案

I don't full understand your question, but I hope I could you help to find what's wrong in your code. I think that you should remove any manipulation of loadonce option of jqGrid. It's unneeded and dangerous. To reload the grid with the server data you need just set datatype to 'json' and reload the grid with .trigger("reloadGrid", [{page: 1, current: true}]); (see here for details). The parameter current: true helps to hold selected row if it will be found in the grid after reloading. The parameter page: 1 can help in case if you use data paging. If the user choosed the second page for example and then reloadGrid will be started it will request the server to load also the second page of the filtered results. So one can have empty grid and the page number 2 in the pager. Resetting the page number to 1 either with respect of setGridParam or with the described above parameter of reloadGrid helps in the cases.

Th problem with setting of loadonce: false could be if the reload of grid will be processed before you set loadonce: true. In the case no local data will be filled in the grid. So the option loadonce: true should be permanently set.

I recommend you additionally to read this answer if you uses server side paging with local sorting of data.

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