PDA

View Full Version : How to override a grid's state when creating it



Perceptive
10 Jun 2015, 7:17 AM
Hi,

I have a stateful grid that I want to hide some columns in, depending on certain factors. The way I'm trying to do this is to set certain columns' 'hidden' property to true before I create the grid. This doesn't work because the state gets loaded and overrides my 'hidden' property.

Gary Schlosberg
10 Jun 2015, 2:24 PM
To clarify, even if a user has made a column visible, you'd like to force it to be hidden when the grid next loads?

Perceptive
11 Jun 2015, 12:40 AM
Yes that's correct. If a user has previously made the column visible I want to be able to force it to be hidden and override this saved state. However I want things like the width and column position to be saved if they subsequently show the column again.

Perceptive
11 Jun 2015, 1:20 AM
I have solved it. Turned out not to be so difficult in the end. The solution was to apply a one-time event listener on the afterrender event. Afterrender seems to be called after the saved state has been applied, so I overrode the 'hidden' property here:


if(some condition that makes we want to hide columns){
column.listeners = {
afterrender: { fn: function(){
this.show();
},
single: true
}
}
}

This means that the column is always hidden when it is first created, but any other aspects of its saved state (width, position, etc.) are not lost, and so if the user chooses to show the column again these settings will still be there.

Gary Schlosberg
11 Jun 2015, 3:26 PM
Glad to hear you found the solution. Thanks for sharing your findings with the community.