PDA

View Full Version : Applying state on Grid Reconfigure



vasanthatextjs
12 Sep 2012, 2:01 AM
In our application, we have a screen with a Selector (ie combobox) and a GridPanel. The selection in the Selector, determines the columns displayed on the GridPanel. As the user changes the selection on the combobox, we reconfigure the gridpanel with the appropriate column configuration pertaining to the user selection. We are able to get this working with the help of Ext.grid.Panel's reconfigure() method using:


// Get user selection
var selection = selectorCombo.getValue();

// Get new column config for user selection and reconfigure grid
var newColumns = getColumnConfigFor(selection);
grid.reconfigure(grid.store, newColumns);

An additional requirement in our application is to support Saving and Restoration of State (of hidden/shown columns with column ordering and column widths) on the GridPanel for every selection. Is this currently supported out-of-the-box in Ext 4.1.1?

If I try to invoke initState() after grid reconfigure, I am having to additionally touch private members (like headerCounter and purgeCache()) of the Ext.grid.header.Container to get it working:


// Get user selection
var selection = selectorCombo.getValue();

// Get new column config for user selection and reconfigure grid
var newColumns = getColumnConfigFor(selection);
grid.reconfigure(grid.store, newColumns);

// Set new stateId for grid and initState
grid.stateId = selection + '-grid-state';
grid.initState();

Am I going in the right direction here? Please advise.

This is my first post in the Ext Forums, and I have tried my best to give as much information. If I can provide any additional information, please let me know.

Thanks.

- Vasanth

scottmartin
13 Sep 2012, 6:12 AM
Another option that may be of interest is to have a look at:
http://www.sencha.com/forum/showthread.php?141207

It may provide more flexibility.

Scott.

vasanthatextjs
18 Sep 2012, 3:07 AM
Thanks for the reply Scott. However, I was not able to get much from the link you pointed me. I felt the post was talking more about storage itself, as opposed to delving into aspects related to Grid reconfigure and state restoration.

vasanthatextjs
18 Sep 2012, 4:01 AM
Actually I have an update to post.

By passing a stateId config as per the documentation (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.column.Column-cfg-stateId) to my grid column configuration, I am able to avoid most of my direct handling with private members of the Ext.grid.header.Container class. My grid is able to save and restore state (for hidden/shown columns and user-altered column widths).

However now, I am falling prey to a new problem. This seems to happen only when I have re-ordered one of my grid columns, and restoring the re-ordered state seems to hit a failure point with an error (see attached screenshot). It happens inside the moveColumn() method of Ext.view.Table class on the highlighted (by code comment) line below:



moveColumn: function(fromIdx, toIdx, colsToMove) {
...

// Move the column sizing header to match
for (i = 0, len = headerRows.length; i < len; ++i) {
tr = headerRows[i];
if (fragment) {
for (j = 0; j < colsToMove; j++) {
fragment.appendChild(tr.cells[fromIdx]);
}
tr.insertBefore(fragment, tr.cells[destinationCellIdx] || null);
} else {
/* IT BREAKS HERE */tr.insertBefore(tr.cells[fromIdx], tr.cells[destinationCellIdx] || null);
}
}
...

I came across a similar issue reported as a bug here (http://www.sencha.com/forum/showthread.php?197132-4.1-RC3-Grid-applyState-NS_ERROR_INVALID_POINTER&p=887960). I wonder if mine is a different symptom of the same bug or a different bug altogether. Any help is deeply appreciated.