我正在使用 EXTJS 网格开发带有分页的复选框网格列表。我需要在执行页面导航时记住所选记录。
详细信息: 1) 转至第 1 页并选择第 1,2 和 3 行。 2)现在导航到页面:2 3)返回页面:1 4) 已选择的第 1,2 和 3 行应显示为已选择
grid中有没有处理这种功能的api?
提前致谢。
最佳答案
感谢您的回复。我通过实现网格插件来实现我的设计。该插件看起来像,
Ext.namespace('Ext.ux.plugins');
Ext.ux.plugins.CheckBoxMemory = Ext.extend(Object,
{
constructor: function(config)
{
if (!config)
config = {};
this.prefix = 'id_';
this.items = {};
this.idProperty = config.idProperty || 'id';
},
init: function(grid)
{
this.view = grid.getView()
this.store = grid.getStore();
this.sm = grid.getSelectionModel();
this.sm.on('rowselect', this.onSelect, this);
this.sm.on('rowdeselect', this.onDeselect, this);
this.store.on('clear', this.onClear, this);
this.view.on('refresh', this.restoreState, this);
},
onSelect: function(sm, idx, rec)
{
this.items[this.getId(rec)] = true;
},
onDeselect: function(sm, idx, rec)
{
delete this.items[this.getId(rec)];
},
restoreState: function()
{
var i = 0;
var sel = [];
this.store.each(function(rec)
{
var id = this.getId(rec);
if (this.items[id] === true)
sel.push(i);
++i;
}, this);
if (sel.length > 0)
this.sm.selectRows(sel);
},
onClear: function()
{
var sel = [];
this.items = {};
},
getId: function(rec)
{
return rec.get(this.idProperty);
}
});
这个插件是从 gird 调用的,
Ext.grid.Gridpanel({
store: 'someStore',
plugins: [new Ext.ux.plugins.CheckBoxMemory({idProperty: "recordID"})]
});
希望这对某人有所帮助。
关于EXTJS 3.3.3 网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8940688/