View Full Version : get the grid state

kamalakarreddy vancha
18 Sep 2014, 11:06 PM
I am using getState() method in extjs grid to get grid state.
var gridState = Ext.getCmp('gridId').getState();

Here it is giving the output like


But i need to get the dataindex of the grid also.
How to do that.....
Help me in this.....

Thanks In Advance
Kamalakar Reddy V

19 Sep 2014, 5:41 AM
I believe you can find the dataindex based on the index of the columns array in the state object. Ext.getCmp('gridid').columnManager.headerCt.gridDataColumns should return an array that matches the state objects columns array.

Here's some code (untested) that should give you the state object with the dataindex for each column:

var gridState = Ext.getCmp('gridid').getState();
var gridColumns = Ext.getCmp('gridid').columnManager.headerCt.gridDataColumns;
for(var i = 0; i < gridState.columns.length; i++){
if(gridState.columns[i].id == gridColumns[i].stateId){
gridStateColumns[i].dataIndex = gridColumns[i].dataIndex;

I'm pretty sure that should work.

Also I wasn't able to find a way to get an item by its stateId, but if you find a way to do that then it would probably be a better solution to do that using the columns id in the state object.

Good luck! I hope this helps!