简体   繁体   English

分页时将选定的行保存在 jqGrid 中

[英]Saving selected rows in a jqGrid while paging

I have a jqGrid with which users will select records.我有一个 jqGrid,用户可以用它来选择记录。 A large number of records could be selected across multiple pages.可以跨多个页面选择大量记录。

The selected rows seem to get cleared out when the user pages through the data.当用户翻阅数据时,选定的行似乎被清除了。 Is it up to the developer to manually track the selected rows in an array?是否由开发人员手动跟踪数组中的选定行? I'm fine doing this, but I'm not sure what the best way is.我这样做很好,但我不确定最好的方法是什么。 I'm not sure I want to be splicing an array whenever any number of records are selected as that seems like it could really slow things down.我不确定我是否想在选择任意数量的记录时拼接数组,因为这似乎真的会减慢速度。

My end goal is to have a jQueryUI dialog that, when closed, while store all the selected rows so I can post it to the server.我的最终目标是有一个 jQueryUI 对话框,当关闭时,同时存储所有选定的行,以便我可以将其发布到服务器。

Note: added aspnetmvc tag only because this is for an MVC app.注意:添加 aspnetmvc 标签只是因为这是一个 MVC 应用程序。

Yes, it's up to the developer to track this selection manually.是的,由开发人员手动跟踪此选择。 You don't have to use an array, though;不过,您不必使用数组; you can use any data structure you like.你可以使用任何你喜欢的数据结构。

I would load each row when selected into the $.data() container.选择时,我会在选择$ .data()容器时加载每行。 This way you can store them away from the grid and when the user is done selecting have a nice packaged data set you can then work with.通过这种方式,您可以将它们存储在远离网格的地方,当用户完成选择时,您可以使用一个很好的打包数据集。

I had a similar requirement and came across this post.我有一个类似的要求,并遇到了这篇文章。 I thought I'd share my solution:我想我会分享我的解决方案:

var selId;
$("#grid").jqGrid({
    ...
    onSelectRow: function(id){ 
        selId = id;
    },
    gridComplete: function() {
        $("#grid").setSelection(selId, true); 
    },
    ...
});

This was for one selection only, but could easily be adapted to multiple selections by making selId an array.这仅适用于一个选择,但可以通过将selId为数组来轻松适应多个选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM