PDA

View Full Version : get the grid state



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


Here it is giving the output like


"{"columns":[{"id":"h4"},{"id":"h1","width":23},{"id":"h2"},{"id":"h3"}]}"


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

mwilliamsShields
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;
}
}
console.log(Ext.JSON.encode(gridState));

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!