我的网格有一个重置按钮,可以重置我的所有列。代码如下所示:
function (response) {
if (response == 'yes') {
Ext.state.Manager.clear(grid.stateId);
var cols = grid.initialConfig.columns
grid.reconfigure(grid.getStore(), cols);
}
});
grid.reconfigure(..)应该重置表的外观,但是当我运行上面的代码时没有任何反应。
我注意到 grid.initialConfig.columns 未定义。为什么这会被定义?是否需要先设置某种初始配置?
(我注意到使用构造函数时可以定义 initialConfiguration 。我改为使用 initComponent 。)
答案 0 :(得分:1)
尝试以下方法:
initComponent : function (){
var me = this;
// we can expect that ExtJS wan't change a config
// but to be really sure we clone the array.
// (You may check this, because I think we don't even need this)
me.columnsCfg = me.columns.slice(0);
....
}
和重新配置
function (response) {
if (response == 'yes') {
// the grid state saves the ordering and visibility
Ext.state.Manager.clear(grid.stateId);
// the store saves the sorting (maybe the filtering to if it)
Ext.state.Manager.clear(grid.getStore().stateId);
grid.getStore().load(); // you may call reload if you want to resend the last load params
grid.reconfigure(grid.getStore(), grid.columnsCfg);
}
});
您对列的操作看起来有点奇怪。您应该只使用配置而不是初始化列。请注意,当网格初始化时,它将覆盖带有初始化列的列引用。你想念的下一点是网格没有保存排序,商店也是如此。因此,您需要将商店重置并重新加载。我必须承认这是理论,我没有对它进行测试。在现实世界中,我面临商店状态的情况被禁用了。
答案 1 :(得分:0)
在我的网格的initComponent(..)中,我添加了 this.initialConfig.columns = this.columns
initComponent : function (){ var me = this; this.columns = createColumns(); this.initialConfig.columns = this.columns;
这有固定的列问题:)但它没有重置排序:(