Friday, June 24, 2011

Extjs : override grid column sorting parameter

During UI upgrade for existing web application I came across a scenario where you want a different parameter to be used for sorting than which is mapped to the displayed column. For e.g: You have a grid with a column 'name' and mapped to 'name' field (dataIndex : 'name'). If sorting is enabled on this column then while sorting, 'name' variable is sent as sort variable. But the server expects it to be 'firstname' as sort variable then either you have to change it at the server side or you can achieve the same at client side.
     With Extjs you can achieve this with just couple of changes. 
Firstly within your column config you have to add an extra attribute viz. customSort with a value that has be used to override the sort param for this column. In above case it would be customSort : 'firstname'
Secondly before loading the store data, for the columns specified with customSort config attribute, you need to replace the sort param with the customSort param .

Code :
Thus by overriding the store sort field you can provide your custom sorting for extjs grid columns.
Hope this helps!

No comments:

Post a Comment