-
2 Nov 2008 7:59 AM #11
Hmm.. It might be me not getting this, but I'll try to explain it once more.
If you take a look at the picture bellow, you'll see a grid using a GroupingView.
The groupField property of the GroupingStore is set to the title column.
As a result of this the grid is grouped by the title field.
Now, I would like groups to be sorted on the "Group Count". To get the number of documents/rows in each group I use: values.rs.length
In the picture you can see that groups are grouped by title, but the "Group Count" is not sorted. I would like the group with 32 reads to be at top, and the group with 5 read to be at the bottom.Code:view: new Ext.grid.GroupingView({ forceFit:true, hideGroupedColumn: true, startCollapsed: true, groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Reads" : "Read"]})' }),
The "Group Count" would be different depending on the column/field I choose to group by, and cannot then be a field in the GroupingStore.
The big question is then: How can I Group By a spesific column using the groupField property, but then sort by the "Group Count" ?
Grid Grouped by the Title field:

Same grid, but sorted by the Read Date field:

Thanks !
Best regards,
Petter
-
25 Nov 2008 6:23 PM #12
question for Animal?
question for Animal?
Hi Animal,
I am trying to get your multi-sorting code working. Here is my call string:
Nothing happens.PHP Code:this.store.sortByFields([{field: 'date', direction: 'DESC'},{field: 'sta', direction: 'ASC'}]);
here is my code structure:
I have tried calling sortByFields in the initComponent and the onRender function without success. Can you give me any assistance?PHP Code:Ext.ns('myNS');
myNS.myGrid = Ext.extend(Ext.grid.EditorGridPanel, {
border:false
,initComponent:function() {
....
....
Ext.apply(this, {
store: this.store
,loadMask: true
,cm: cm
....
});
Verigo.myGrid.superclass.initComponent.apply(this, arguments);
} // end of initComponent
,onRender:function() {
....
} // end of function onRender
});
Ext.reg('myGrid', myNS.myGrid);
Cheers,
Trav.
-
30 Aug 2009 9:38 PM #13
[Ext 3.0]Multi-column sort - needs a refresh ?
[Ext 3.0]Multi-column sort - needs a refresh ?
Thanks Christian, Animal.
Above sortData function works fine for me in Ext 3.0. Though the 'datachanged' event is generated my grid is not refreshing the sort data. My code:
Am I missing anything here ?Code:Ext.override(Ext.data.Store, { sortData : function(f, direction){ // a test sort info var multipleSortInfo = [{field: 'number', direction: 'ASC'}, {field: 'name', direction: 'DESC'}]; direction = direction || 'ASC'; var st = this.fields.get(field).sortType; var fn = function(r1, r2) { var ret = 0; for (i = 0; (multipleSortInfo !== undefined && ret == 0 && i < multipleSortInfo.length); i++) { var v1 = st(r1.data[field]), v2 = st(r2.data[field]); var x1 = r1.data[multipleSortInfo[i].field], x2 = r2.data[multipleSortInfo[i].field]; var dir = (direction != multipleSortInfo[i].direction) ? direction .toggle("ASC", "DESC") : direction; ret = (x1 > x2) ? 1 : ((x1 < x2) ? -1 : 0); if (dir == 'DESC') ret = -ret; }; return ret; }; this.data.sort(direction, fn); if (this.snapshot && this.snapshot != this.data) { this.snapshot.sort(direction, fn); } }
-
26 Oct 2009 3:35 AM #14
Hi guys,
Egs, have you found a solution to ordering by the group count as I am trying to do the same thing.
I am producing a list of people and the forum posts they have made and I would like to order by the number of posts. I am grouping on the name and I am also bringing back the number of times they have posted but it will not let me order by that number, it is still ordering by the name. I have tried using both sortInfo and store.setDefaultSort but the grid is still sorting by the name.
Any ideas?
-
27 Oct 2009 12:52 AM #15
For those of you wondering how this is done, if you set the remoteGroup config option to true then you can specify your own grouping in the method you use to get the store, in my case a stored procedure. Using this you can order the on the DB side and handle any other re-ordering in the XHR call.
Dusted
-
25 Nov 2009 2:06 AM #16
Require Custom Sorting in GridPanel
Require Custom Sorting in GridPanel
Hi,
I am facing a similar issue. I have 3 columns - Period,Name and Type. Type can be 'Low','Medium','High'. However, when I click on Sort Asc in the header, I want the display as follows:
Low
Medium
High
which is not necessarily alphabetical order.
Is there any way to define custom sorting. I tried as follows but doesnt work:
var config = {
sortableField: 'Type.Name'
};
Ext.apply(this, {
store: new Ext.data.Store({
reader: new Ext.data.JsonReader(
{
id: 'Id'
},
Ext.data.Record.create([
{ name: 'Id', mapping: 'Id' },
{ name: 'ReportingPeriod.Name', mapping: 'ReportingPeriod.Name' },
{ name: 'Name', mapping: 'Name' },
{ name: 'Type.Name', mapping: 'Type.Name', sortType: this.sortTypes }
])
)
}),
columns: [
{ header: "Id", width: 20, sortable: true, dataIndex: 'Id', hidden: true },
{ header: "Period", width: 175, sortable: true, dataIndex: 'ReportingPeriod.Name' },
{ header: "Name", width: 125, sortable: true, dataIndex: 'Name', minWidth: 100 },
{ header: "Type", width: 125, sortable: true, dataIndex: 'Type.Name', minWidth: 100 }
],
height: 150,
width: 400,
autoScroll: true,
closable: true,
sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {
rowselect: function(sm, rowidx, rec) {
}
}),
viewConfig: {
forceFit: true
}
});
----other code--,
sortTypes: function(value) {
switch (value.toLowerCase()) {
case'Low':
return 1;
case'Medium':
return 2;
case'High':
return 3;
}
return 4;
},
Any help is appreciated..Thanks in advance..
-
25 Nov 2009 5:55 AM #17
typo in sortTypes ??? always returns 4 ??
typo in sortTypes ??? always returns 4 ??
Do the function always returning 4 ??
sortTypes: function(value) {
switch (value.toLowerCase()) {
case'Low': ====> should it be 'low' here ?
return 1;
case'Medium': ====> medium
return 2;
case'High': ====> high
return 3;
}
return 4;
},
-
27 Nov 2009 11:21 AM #18
@yaminih
Are you loading the data into the grid using a query? In my case i was and gave high, medium and low the Id's 1,2 and 3 so that i could order them as you are trying.
This only works if you are using a database call though...
-
9 Jul 2010 12:19 AM #19
Animal,
I just wanted to check if I can use your sortByFields() in Ext 3.0 as well. If so, where do I call that function? I tried to call it in sortChange listener of my gridpanel but it goes into endless recursion


Reply With Quote