[英]Ext JS 4.2.1 - grid with paging - checkbox state lost
I have an ExtJS grid that has a PagingToolbar for (remote) paging, and a checkbox column defined as: 我有一个ExtJS网格,该网格具有用于(远程)分页的PagingToolbar和一个定义为的复选框列:
{
dataIndex : 'selected',
xtype: 'checkcolumn',
width : 60
}
However, if I check a box and then page forwards and backwards, the checkbox state is not saved - all the checkboxes are unchecked. 但是,如果我选中一个复选框,然后向前和向后翻页,则不会保存复选框状态-所有复选框均未选中。
I guess since the store only contains data for the current page (from the server), I need some way of storing the state for rows that are not in the current page of data, and then reinstating the checkboxes when I return to that page. 我猜因为存储只包含当前页面(来自服务器)的数据,所以我需要某种方式来存储不在当前数据页面中的行的状态,然后在返回该页面时恢复复选框。
Is there a best practice, or example of storing the checkbox state in the store while paging? 有最佳实践,还是在分页时将复选框状态存储在商店中的示例?
Well, that's so low-level work that no one has yet thought to make a "best practice" for it. 嗯,这是低级的工作,以至于没有人考虑过为此做出“最佳实践”。 Eg
例如
beforeload:function(store) {
if(!store.checkedItems) store.checkedItems = [];
store.each(function(item) {
store.checkedItems[item.get("Id")] = item.get("selected");
});
},
load:function(store) {
if(!store.checkedItems) store.checkedItems = [];
store.each(function(item) {
item.set("selected",store.checkedItems[item.get("Id")]);
});
}
or 要么
beforeload:function(store) {
if(!store.checkedItems) store.checkedItems = [];
store.each(function(item) {
store.checkedItems[item.get("Id")] = {selected: item.get("selected") }; // extensible if you want to keep more than one checkbox...
});
},
load:function(store) {
if(!store.checkedItems) store.checkedItems = [];
store.each(function(item) {
item.set(store.checkedItems[item.get("Id")]);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.