我的应用程序中有一个无限滚动的网格面板(ExtJs 4.2.1),类似于 this example .用户可以单击刷新按钮,然后必须使用数据库中的数据更新网格的行。我在刷新按钮处理程序中调用 store.load(),并且我的数据得到更新。这适用于网格面板的第一行(第 1 页的记录)。但是如果用户向下滚动网格,它就不起作用。 store.load 之后,grid 将滚动位置重置到顶部。
我正在寻求一种解决方案来重新加载商店并刷新保持当前选择以及当前滚动位置的网格。好消息:我有商店中每条记录的全局索引。
这是我的代码,数据库中有数千个条目。
网格面板:
Ext.define('MyApp.view.MyGrid', {
extend: 'Ext.grid.Panel',
requires:[ 'Ext.grid.plugin.BufferedRenderer'],
alias: 'widget.myGrid',
plugins: 'bufferedrenderer',
loadMask: true,
selModel: {
mode: 'MULTI',
pruneRemoved: false
},
itemSelector: 'div.workspaceItemSelector',
overItemCls: 'workspaceItemMouseOver',
trackOver: true,
autoScroll: true,
verticalScroller: { variableRowHeight: true },
defaultSortOrder: 'ASC',
// and some column definitions ...
});
店铺:
Ext.define('MyApp.store.MyStore', {
extend: 'Ext.data.Store',
autoLoad: false,
buffered: true,
pageSize: 100,
leadingBufferZone: 100,
remoteSort: true,
model: 'MyApp.model.MyModel',
storeId: 'myStore',
proxy: {
type: 'rest',
url: 'someUrl',
reader: { type: 'json', totalProperty: 'total', root: 'items' }
}
});
有一个solution对于无缓冲网格,这对我不起作用。
最佳答案
关于负载 Controller 功能:
loadStoreFunction : function (grid) {
var storeGrid = grid.getStore();
var currentElement = grid.getSelectionModel().getSelection();
storeGrid.load({
scope: this,
callback: function(records, operation, success) {
grid.getView().focus();
grid.getSelectionModel().select("index of currentElement"); // last position.
grid.getSelectionModel().select(storeGrid.getRange().length-1); // last insert
storeGrid.loadPage(1+(index/totalCount),options); // Load row's page calculated.
}
});
}
关于无限滚动网格面板的 ExtJs 刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17229095/