Ext JS 4.2.1 - grid with paging - checkbox state lost

最后都变了- 提交于 2019-12-25 09:13:09

问题


I have an ExtJS grid that has a PagingToolbar for (remote) paging, and a checkbox column defined as:

{
    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?


回答1:


Well, that's so low-level work that no one has yet thought to make a "best practice" for it. E.g.

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")]);
    });
}


来源:https://stackoverflow.com/questions/38241152/ext-js-4-2-1-grid-with-paging-checkbox-state-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!