Grid.reconfigure在extjs中不工作
我的网格有一个重置按钮,用来重置我的所有列。代码如下所示:Grid.reconfigure在extjs中不工作,extjs,extjs4,Extjs,Extjs4,我的网格有一个重置按钮,用来重置我的所有列。代码如下所示: function (response) { if (response == 'yes') { Ext.state.Manager.clear(grid.stateId); var cols = grid.initialConfig.columns
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。)在我的initComponent(..)中,我为我的网格添加了this.initialConfig.columns=this.columns
这解决了列问题:),但不会重置排序:(请尝试以下操作:
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);
}
});
您对列所做的操作看起来有点奇怪。您应该只使用简单的配置,而不使用初始化的列。请注意,当网格初始化时,它将使用初始化的列覆盖列引用。您遗漏的下一点是,不是网格保存排序,而是存储保存排序。因此您需要重置我必须承认这是理论,我没有测试它。在现实世界中,我面临的存储状态被禁用。如果
grid.initialConfig.columns
未定义,你怎么能期望grid.reconfigure
工作?是的,你是对的。我在下面通过设置initialConfig.colu来回答自己mns在我的initComponent中。只是我以前从未在任何演示中看到过这样使用的代码。
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);
}
});