-
18 Feb 2013 4:45 AM #1Sencha Premium Member
- Join Date
- Jun 2011
- Location
- Kaiserslautern, Germany
- Posts
- 7
- Vote Rating
- 0
- Answers
- 2
Answered: Custom sort in tree column. Sorter in store impelmented, but the column uses its own
Answered: Custom sort in tree column. Sorter in store impelmented, but the column uses its own
hi all
this is the code in tree store
When the tree is first time loaded (on page load) the items are sortet using the sorter I implemented in store. But when I click on the header the tree uses its own sorter.Code:Ext.define('data.store.AssetTreeStore', { extend: 'Ext.data.TreeStore', sorters: [ { // natural sort sorterFn: function (rec1, rec2) { <some code> } ] ... });
What I'm doing wrong?
-
Best Answer Posted by Kotolom
I've got it.
I have to add the 'sort' function to the store.
Code:sort: function(sorters, direction) { var me = this; if(sorters && sorters.property == 'title') { if(sorters.direction == 'ASC') { return this.doSort(function(rec1, rec2) { return Util.String.compareNatural(rec1.get('title'), rec2.get('title')); }); } else { return this.doSort(function(rec1, rec2) { return -Util.String.compareNatural(rec1.get('title'), rec2.get('title')); }); } } return me.callParent(arguments); }
-
22 Feb 2013 9:14 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3161
When you click on the tree grid column header, it will only use the one sorter based on the header. It won't add a sort to the existing array of sorters.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 Feb 2013 1:27 AM #3Sencha Premium Member
- Join Date
- Jun 2011
- Location
- Kaiserslautern, Germany
- Posts
- 7
- Vote Rating
- 0
- Answers
- 2
Well, that's clear to me.
But when you look at this example http://jsfiddle.net/cvdNW/3/
you will find the sort implemented in store and used on header click.
So the right question is: how can I use a custom sort on header click in a tree column?
And I can't apply it to a field in the model, because this would affect other components thas are using the model.
All solutions I found use the store to impelment a custom sort.
-
4 Mar 2013 8:11 AM #4Sencha Premium Member
- Join Date
- Jun 2011
- Location
- Kaiserslautern, Germany
- Posts
- 7
- Vote Rating
- 0
- Answers
- 2
I've got it.
I have to add the 'sort' function to the store.
Code:sort: function(sorters, direction) { var me = this; if(sorters && sorters.property == 'title') { if(sorters.direction == 'ASC') { return this.doSort(function(rec1, rec2) { return Util.String.compareNatural(rec1.get('title'), rec2.get('title')); }); } else { return this.doSort(function(rec1, rec2) { return -Util.String.compareNatural(rec1.get('title'), rec2.get('title')); }); } } return me.callParent(arguments); }


Reply With Quote