在 extjs 我有一个网格。此网格每 ** 秒刷新一次。为了保持网格选择,我使用了这个:
Ext.define('PersistantSelectionGridPanel', {
extend: 'Ext.grid.Panel',
selectedRecords: [],
initComponent: function () {
this.callParent(arguments);
this.getStore().on('beforeload', this.rememberSelection, this);
this.getView().on('refresh', this.refreshSelection, this);
},
rememberSelection: function (selModel, selectedRecords) {
if (!this.rendered || Ext.isEmpty(this.el)) {
return;
}
this.selectedRecords = this.getSelectionModel().getSelection();
this.getView().saveScrollState();
},
refreshSelection: function () {
if (0 >= this.selectedRecords.length) {
return;
}
var newRecordsToSelect = [];
for (var i = 0; i < this.selectedRecords.length; i++) {
record = this.getStore().getById(this.selectedRecords[i].getId());
if (!Ext.isEmpty(record)) {
newRecordsToSelect.push(record);
}
}
this.getSelectionModel().select(newRecordsToSelect);
Ext.defer(this.setScrollTop, 30, this, [this.getView().scrollState.top]);
}
});
但这在一个网格中不起作用,我不知道为什么。这是刷新功能:
refreshSeconds = refreshRate * 1000;
refreshData = {
run: function () {
NL.store.load();
},
interval: refreshSeconds
}
Ext.TaskManager.start(refreshData)
这是网格(没有列)
var grid = Ext.create('PersistantSelectionGridPanel', {
autoscroll: true,
region: 'center',
store: NL.store,
multiSelect: false,
stateful: true,
loadMask: false,
stateId: 'stateGridEvents',
viewConfig: {
stripeRows: true
},
columns: [{
但是当商店重新加载时,选择会丢失。我需要改变什么?