-
8 Jun 2011 10:24 AM #1
Grid sorting by different dataIndex
Grid sorting by different dataIndex
I know this is not a bug, but a feature request, but since I don't have permissions to post there, I'll post it here...
I always run into a problem with grids, ordering and sorting. The problem is very common, you are displaying in a grid a field from another object, so you show the name of the object, but filter by it's id. Your column config is something like:
The problem comes when you want to sort, now if you put sortable:true then you will be sorting by id not name (which is what a user expects). You could change the dataIndex to "category_name", but then the filter would be in the wrong field. So the thing is that you can't specify different fields for sorting and filtering in a column.Code:{ dataIndex: 'category_id', header: 'Category', renderer: function(value, meta, record, rowIndex, colIndex, store, view) { return record.get('category_name'); }, filter: { type: "list", store: "categorystore" } }
This can be solved in two ways, adding some config to the filter to specify which column should filter or add a config to the sorting. It tried it both, but since the code for the filtersfeature is still in development (in ext 4.0.2RC it's different than in RC1) I figured it was simpler to do it for the sorting. Here's the override:
As you can see you can specify an additional option for the column 'sortIndex' that specifies which field to use. It could be implemented by passing the field in the 'sort' config, but that may break some applications that for some reason are sending a string in the sortable config.Code:Ext.override(Ext.grid.column.Column, { getSortParam: function() { return this.sortIndex || this.dataIndex; } });
Is there any possibility of adding this to ext core??
-
25 Sep 2012 7:52 PM #2
Actually I came to exactly the same solution.
It would be great to have a separate config for the sorting/filtering.
-
26 Sep 2012 1:01 PM #3
Uhm, guys, why closing without any comments?!
-
26 Sep 2012 2:41 PM #4
You can specify custom sorting types for fields.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
26 Sep 2012 2:44 PM #5
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote
