PDA

View Full Version : [2.0b1][CLOSED] Grouping and sorting



lvanderree
14 Oct 2007, 3:56 AM
Last night I replied to a post about a problem in the help-topic (http://extjs.com/forum/showthread.php?t=14958), but I think it is more appropriate over here. (Ps. Title should say 2.0B1)

I added some screenshots and the JSON-data to make the problem more clear.

I think the problem is that because a grid can only store one sort-column, you get unexpected results when you sort in a grouped-grid.

I for example have an overview of assignments, which I show in descending order (red). Every assignment can have one or more parcels (green) which I also show in descending order. See image and JSON-data:

http://fun4me.demon.nl/%7Eleon/Group-descending.png

See the end of the lines for the parcel-subject Data.


{totalCount:"3", data:[

{"assignment_subject":"3333","assignment_vessel":"Star Bonaire","assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"8", "assignmentparcel_subject":"3333d"},

{"assignment_subject":"3333", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"7", "assignmentparcel_subject":"3333c"},

{"assignment_subject":"3333","assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM","assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"6", "assignmentparcel_subject":"3333b"} ,

{"assignment_subject":"3333", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"5", "assignmentparcel_subject":"3333a"}

,

{"assignment_subject":"2222", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 29, 2007 1:12 AM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 29, 2007 1:12 AM", "assignment_assignmentid":"2", "assignmentparcel_assignmentparcelid":"", "assignmentparcel_subject":""}

,

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"4", "assignmentparcel_subject":"1111d"},

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"3", "assignmentparcel_subject":"1111c"},

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"2", "assignmentparcel_subject":"1111b"},

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"1","assignmentparcel_subject":"1111a"}

]}

Now I click on the Parcel-column-header, to change the sort-order of the parcels to ascending. The sorting is done remote and the JSON-data I receive now contains the assignments still in descending order, and the parcels in ascending order, but as you can see the Assignments are now also shown in ascending order...

http://fun4me.demon.nl/%7Eleon/Group-ascending.png

See the end of the lines for the parcel-subject Data.


{totalCount:"3", data:[

{"assignment_subject":"3333","assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"5", "assignmentparcel_subject":"3333a"},

{"assignment_subject":"3333", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"6", "assignmentparcel_subject":"3333b"},

{"assignment_subject":"3333","assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"7", "assignmentparcel_subject":"3333c"},

{"assignment_subject":"3333", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"wouter", "assignment_created_at":"October 5, 2007 10:19 AM", "assignment_sf_guard_user_related_by_updated_by":"wouter", "assignment_updated_at":"October 5, 2007 10:19 AM", "assignment_assignmentid":"3", "assignmentparcel_assignmentparcelid":"8", "assignmentparcel_subject":"3333d"}

,

{"assignment_subject":"2222", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 29, 2007 1:12 AM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 29, 2007 1:12 AM", "assignment_assignmentid":"2", "assignmentparcel_assignmentparcelid":"", "assignmentparcel_subject":""}

,

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"1", "assignmentparcel_subject":"1111a"},

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"2", "assignmentparcel_subject":"1111b"},

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"3", "assignmentparcel_subject":"1111c"},

{"assignment_subject":"1111", "assignment_vessel":"Star Bonaire", "assignment_sf_guard_user_related_by_created_by":"admin", "assignment_created_at":"August 22, 2007 3:38 PM", "assignment_sf_guard_user_related_by_updated_by":"admin", "assignment_updated_at":"August 22, 2007 3:38 PM", "assignment_assignmentid":"1", "assignmentparcel_assignmentparcelid":"4", "assignmentparcel_subject":"1111d"}

]}
I suspect this is due to extjs only being able to sort on one column, maybe a nice solution can be found in this implementation: http://tablesorter.com/docs/

jsakalos
18 Oct 2007, 5:17 PM
Yes, this can be seen also on examples http://extjs.com/deploy/ext-2.0-beta1/examples/grid/grouping.html Grouping by Industry and clicking on company then changes the order of groups and items as well.

We will investigate it further and we will let you know what can be done about it.

jack.slocum
20 Oct 2007, 7:25 AM
Do you have remoteSort set to true in your config? Can you post up some code.

With remoteSort set to true, the grid and store will not reorder the records, you need to return them in the correct order. e.g. if the store passes you a groupBy of columnA and a sort of columnB, you will need to sort the data you return by columnA, then by columnB.

The groups always display in ascending order, it does not match the order of data (unless you return the data in reverse).

Since you are using remote sorting, there is no way the ordering can be a bug in Ext as Ext does not reorder the data. You need to return it in the order you want it displayed.

lvanderree
21 Oct 2007, 3:06 AM
Hi Jack I don't think you can close this bug, because I think there does is a bug in extjs.

As you could see in my JSON output, I provide the JSON-data in descending order, for the assignment-subjects (the column on which I group). And this only work out if I don't sort on any other column. As soon as I start sorting my data on for example ascending parcel-subjects (the first column you see) both the parcel-subjects as well as the assignment-subjects get sorted ascending, even though in the JSON-data everything is in the correct order (desc assignments and asc parcels).

Here is the code of my (remotely sorting) datastore:


ds = new Ext.data.GroupingStore({
// load using HTTP
url: '/backend_dev.php/assignment/jsonList',

// create the Data reader
reader: new Ext.data.JsonReader({
id: 'assignmentparcel_assignmentparcelid',
root: 'data',
totalProperty: 'totalCount',
}, [
// add the mainclass primary key to the field mapping
{name: 'assignment_assignmentid', mapping: 'assignment_assignmentid'}
// add the subclass primary key to the field mapping
,{name: 'assignmentparcel_assignmentparcelid', mapping: 'assignmentparcel_assignmentparcelid'}
// set up the mainclass fields mapping
,{name: 'assignment_subject', mapping: 'assignment_subject'}
,{name: 'assignment_clientcompany', mapping: 'assignment_clientcompany'}
,{name: 'assignment_vesselid', mapping: 'assignment_vesselid'}
,{name: 'assignment_agentcompany', mapping: 'assignment_agentcompany'}
,{name: 'assignment_berth', mapping: 'assignment_berth'}
// set up the subclass fields mapping
,{name: 'assignmentparcel_subject', mapping: 'assignmentparcel_subject'}
,{name: 'assignmentparcel_productnameid', mapping: 'assignmentparcel_productnameid'}
,{name: 'assignmentparcel_quantity', mapping: 'assignmentparcel_quantity'}
,{name: 'assignmentparcel_stowage', mapping: 'assignmentparcel_stowage'}
]),

groupField: 'assignment_subject',

sortInfo:{field: 'assignment_subject', direction: "desc"},

// turn on remote sorting
remoteSort: true
});


If you want to see more code, please ask, but because everything gets generated, and it is very much work in process, the code requires some clean-up (improved aligning, cleanup of commented-lines)

jack.slocum
21 Oct 2007, 7:56 PM
As I stated above, the client code does not reorder the data if remoteSort is true. If you are using remote sorting and you want the groups in descending order you must return them in descending order.

lvanderree
22 Oct 2007, 5:38 AM
I'm sorry, but it really does not work like you say.

As I stated above, I am using remote-sorting, I return the JSON-data in the order I want to see it and it works the first time, but as soon as you sort one of the columns the grouping gets sorted as well.

I have created a small and simple live demo to show it to you:
http://fun4me.demon.nl/test/test_dev.php/item

When you look at this list, you see a list of items, grouped per group (or groEp as it says in the json-data). Both the groups as well as the items are sorted descending.

Now press the Name-column-header once, to change the sort-direction of the items. You will see that the groups will show up in ascending order as well! If you use Firebug, you can see that my JSON-Data is still sending the groups in descending order.

And to further support my statement, while having the items sorted ascending. enter the URL again in the same browser! (I (or actually symfony) use(s) cookies to store the sort-direction, so now you load the entire page again, which gives you back the descended groups, with ascending items in it (because this order is stored in a session cookie).

To start all over again, you have to remove your session-cookie...

Do you now agree it probably is something in the Extjs library, or am I really missing the point?

jack.slocum
22 Oct 2007, 1:16 PM
Your store isn't configured properly. Try adding remoteGroup:true. Local grouping will only work with local sorting as the 2 are intertwined.

lvanderree
22 Oct 2007, 2:17 PM
Ah thank you,

so besides remoteSort: true, you should also set remoteGroup:true, I did not knew nor expect this.

Thanks

jratcliff
3 Nov 2008, 4:59 PM
Yes, this can be seen also on examples http://extjs.com/deploy/ext-2.0-beta1/examples/grid/grouping.html Grouping by Industry and clicking on company then changes the order of groups and items as well.

We will investigate it further and we will let you know what can be done about it.

@jsakalos - I'm seeing the same issue you have described that happens with the Grouping example. Is there a property that needs to be set or is this a bug? Basically, I need to sort the groupBy in descending order and have it stay that way while other columns are sorted in ascending or descending order.

jsakalos
4 Nov 2008, 1:10 AM
This was related to 2.0 beta. Is the problem apparent also in 2.2?

jratcliff
4 Nov 2008, 8:30 AM
This was related to 2.0 beta. Is the problem apparent also in 2.2?

Yes, if you go to the latest examples at "/deploy/dev/examples/" and run the grouping example the same behavior happens as well.

http://extjs.com/deploy/dev/examples/grid/grouping.html

From this grouping example it starts with the grouping done on the industry column and sorted in ascending order. If you click on the industry column twice to sort the group in descending order you will see that "Services" is now the the first group listed. Now, if you click on the company column to sort it, the industry group is resorted as well. The behavior I want is for the group to "stick" and not resort while the other columns resort when clicked.

Thanks for looking into this!

jsakalos
4 Nov 2008, 9:01 AM
Yes, I see what you mean. However, I'm afraid that the behavior is not configurable currently and that what is sorted in fact are underlying records with no regard to grouping. You may want to post it as a feature request.

jratcliff
7 Nov 2008, 6:42 AM
Yes, I see what you mean. However, I'm afraid that the behavior is not configurable currently and that what is sorted in fact are underlying records with no regard to grouping. You may want to post it as a feature request.

ok, thanks!

Ajit Kumar Subudhi
2 Dec 2008, 9:09 AM
Hi,

I am facing a problem.I want to grouping in grid but I don't want to put any "sortInfo", while grouping.

:
==========================================================
var store = new Ext.data.GroupingStore({
reader: reader,
//sortInfo:{field: 'Name', direction: "asc"},
groupField:'ID',
proxy : new Ext.data.HttpProxy({
url: 'Test.ashx',
method: 'GET'
})
});
store.load();

=============================================================

Is it possible ?

Please reply.

Thanks in advance
Ajit

jsakalos
2 Dec 2008, 1:06 PM
Have you tried to remove sortInfo and has it produced some errors?

I think that if you sort on groupField it doesn't matter anyway, does it?

Ajit Kumar Subudhi
3 Dec 2008, 8:23 AM
Thanks for your reply. Its working now. thr might be some other issue.