Hybrid View
-
21 Feb 2012 1:03 PM #1
Answered: How to group a list but change the group order...
Answered: How to group a list but change the group order...
Hi,
I am wondering if it is possible to change the order of a grouped list. For example:
This list will be grouped by the group field but the order of the groups would be as follows:Code:Ext.define('a.store.S', { extend: 'Ext.data.Store', config: { model: 'a.model.S', grouper: { groupFn: function (record) { return record.get('group').substr(2); } }, data: [ {title: 'a title', group: '2-A group', url: 'some url'}, {title: 'b title', group: '2-A group', url: 'some url'}, {title: 'c title', group: '1-B group', url: 'some url'}, {title: 'd title', group: '1-B group', url: 'some url'}, {title: 'e title', group: '0-C group', url: 'some url'}, ]
A group
B group
C group
If I do not use the substr method then the groups would be in the order that I desire but with the undesirable prefix:
0-C group
1-B group
2-A group
Is it possible to make the groups in this list ordered and displayed as follows?
C group
B group
A group
-
Best Answer Posted by Soenhay
Thanks to j.k's response:
I found this link:j.kYou can use sortProperty or sorterFn to sort your groups in any order you want to:
http://docs.sencha.com/touch/2-0/#!/...t.util.Grouper
http://www.sencha.com/forum/showthre...e-in-ST2-beta1
Which lead to this solution:
Which will make the groups with the following titles and order:Code:Ext.define('a.store.S', { extend: 'Ext.data.Store', config: { model: 'a.model.S', autoLoad: true, sorters: 'title', grouper: { sortProperty: 'group_index', groupFn: function (record) { return record.get('group_title'); } }, data: [ {title: 'a title', group_title: 'A group', group_index: '1'}, {title: 'b title', group_title: 'A group', group_index: '1'}, {title: 'c title', group_title: 'B group', group_index: '2'}, {title: 'd title', group_title: 'B group', group_index: '2'}, {title: 'e title', group_title: 'C group', group_index: '0'}, ] }
C group
---e title
A group
---a title
---b title
B group
---c title
---d title
I changed the order from my original post to make it more clear.
-
21 Feb 2012 1:06 PM #2
try:
in your grouper configPHP Code:groupDir: "DESC"
-
21 Feb 2012 1:25 PM #3
I do not mean grouping descending or ascending..... I mean to have the list grouped by whatever I want.. not necessarily in alphabetical or numerical or ascending/descending order......
-
21 Feb 2012 1:28 PM #4
You can use sortProperty or sorterFn to sort your groups in any order you want to:
http://docs.sencha.com/touch/2-0/#!/...t.util.Grouper
-
21 Feb 2012 1:31 PM #5
Cool, that sounds more like what I want.. I am looking into it now.. Thanks for the quick response!
-
21 Feb 2012 1:56 PM #6
Thanks to j.k's response:
I found this link:j.kYou can use sortProperty or sorterFn to sort your groups in any order you want to:
http://docs.sencha.com/touch/2-0/#!/...t.util.Grouper
http://www.sencha.com/forum/showthre...e-in-ST2-beta1
Which lead to this solution:
Which will make the groups with the following titles and order:Code:Ext.define('a.store.S', { extend: 'Ext.data.Store', config: { model: 'a.model.S', autoLoad: true, sorters: 'title', grouper: { sortProperty: 'group_index', groupFn: function (record) { return record.get('group_title'); } }, data: [ {title: 'a title', group_title: 'A group', group_index: '1'}, {title: 'b title', group_title: 'A group', group_index: '1'}, {title: 'c title', group_title: 'B group', group_index: '2'}, {title: 'd title', group_title: 'B group', group_index: '2'}, {title: 'e title', group_title: 'C group', group_index: '0'}, ] }
C group
---e title
A group
---a title
---b title
B group
---c title
---d title
I changed the order from my original post to make it more clear.


Reply With Quote