Oliver Watkins
Oliver Watkins

Reputation: 13509

Grid.reconfigure not working in extjs

I have a reset button for my grid that is supposed to reset all my columns. Code looks like this :

               function (response) {
                    if (response == 'yes') {

                        Ext.state.Manager.clear(grid.stateId);

                        var cols = grid.initialConfig.columns

                        grid.reconfigure(grid.getStore(), cols);
                    }
                });

grid.reconfigure(..) is supposed to reset how the table looks, however nothing happens when I run the code above.

I noticed that grid.initialConfig.columns is undefined. Why would this be undefined? Is there some kind of initial configuration that needs to be set first?

(I notice that when using a constructor you can define an initialConfiguration. I used initComponent instead.)

Upvotes: 0

Views: 5544

Answers (2)

sra
sra

Reputation: 23973

Try the following:

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

    ....
}

and the reconfigure

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);
     }
});

It looks a bit weird what you are doing with the columns. You should stay with simply configurations and not initialized columns. Note that while the grid get initialized it will override the columns reference with the initialized columns. The next point you miss is that not the grid saves the sorting, the store does. So you will need to reset the store to and reload it. I must admit that this is theory and that I don't tested it. In the the real world cases that I faced the store state was disabled.

Upvotes: 2

Oliver Watkins
Oliver Watkins

Reputation: 13509

In my initComponent(..) for my grid I added this.initialConfig.columns = this.columns

initComponent : function (){
    var me = this;

    this.columns = createColumns();

    this.initialConfig.columns = this.columns;

This has fixed column issues :) But it doesn't reset sorting :(

Upvotes: 1

Related Questions