【问题标题】:Grid.reconfigure not working in extjsGrid.reconfigure 在 extjs 中不起作用
【发布时间】:2014-06-27 12:40:25
【问题描述】:

我的网格有一个重置按钮,应该重置我的所有列。代码如下所示:

               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。)

【问题讨论】:

  • 如果grid.initialConfig.columns 未定义,你怎么能指望grid.reconfigure 工作?
  • 是的,你是对的。我通过在我的 initComponent 中设置 initialConfig.columns 来回答自己。只是我之前从未在任何演示中看到过这样使用的代码。

标签: extjs extjs4


【解决方案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);
     }
});

您对列所做的操作看起来有点奇怪。您应该保留简单的配置而不是初始化列。请注意,当网格初始化时,它将用初始化的列覆盖列引用。您错过的下一点是,不是网格保存排序,而是存储。因此,您需要将商店重置为并重新加载。我必须承认这是理论,我没有测试过。在我面临的真实世界案例中,商店状态被禁用。

【讨论】:

    【解决方案2】:

    在我的网格的 initComponent(..) 中,我添加了 this.initialConfig.columns = this.columns

    initComponent : function (){
        var me = this;
    
        this.columns = createColumns();
    
        this.initialConfig.columns = this.columns;
    

    这已经解决了列问题 :) 但它不会重置排序 :(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-26
      • 2012-06-29
      • 2013-07-15
      • 2013-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多