PDA

View Full Version : Sorting Order gets lost when you use groupBy



Jogilein
22 May 2010, 6:13 AM
Hi,

Detailed description of the problem
using a Grid with Paging and Grouping works fine. But everytime you select another column for grouping (by passing the name of the column to groupBy(String)) the information about the column to sort by and the sorting order gets lost. The bug appears if you use setRemoteGroup(true) and setGroupOnSort(false).

GXT version
2.1.1

Host mode / web mode / both
only tried web mode

Browser and version
FireFox 3.6, Internet Explorer 8

Operating System
Windows XP

Sample code
The grouping store is set up ass following:


final GroupingStore<BaseModelData> groupingStore = new GroupingStore<BaseModelData>( loader);

// set some default attributes
groupingStore.setGroupOnSort(false);
groupingStore.setRemoteGroup(true);

// set the passed attributes
groupingStore.groupBy(gridBean.getGroupByField());
Whenever load is fired the configuration is checked, whereby the last configuration is stored in config (the sorting on server side works fine and the data is sorted by group ASC and than by all passed fields (depending on the Sorting Order))...


if (loadConfig instanceof GroupingLoadConfig) {
final GroupingLoadConfig groupingLoadConfig = (GroupingLoadConfig) loadConfig;

config.set("groupBy", groupingLoadConfig.getGroupBy());
} else if (loadConfig instanceof PagingLoadConfig) {
final PagingLoadConfig pagingLoadConfig = (PagingLoadConfig) loadConfig;

config.set("limit", pagingLoadConfig.getLimit());
config.set("offset", pagingLoadConfig.getOffset());
config.setSortDir(pagingLoadConfig.getSortDir());
config.setSortField(pagingLoadConfig.getSortField());
} else {
final ListLoadConfig listLoadConfig = (ListLoadConfig) loadConfig;

config.setSortDir(listLoadConfig.getSortDir());
config.setSortField(listLoadConfig.getSortField());
}

asyncService.getPagedData(configName, gridBean.getName(),
gridBean.getParameters(), config, callback);

Jogilein
23 May 2010, 9:48 AM
... but maybe I'm wrong...

So the refreshing of the ColumnHeader is wrong



if (container instanceof Grid) {
Grid grid = (Grid)container;
SortInfo sortInfo = grid.getStore().getSortState();
if (sortInfo != null && sortInfo.getSortField() != null) {
ColumnModel cm = grid.getColumnModel();
ColumnConfig column = cm.getColumnById(sortInfo.getSortField());
updateSortIcon(cm.indexOf(column), sortInfo.getSortDir());
}
}

Is the code used (com.extjs.gxt.ui.client.widget.gridColumnHeader#refresh)... and cm.getColumnById(sortInfo.getSortField()); will always return null cause as far as I remember the SortField is defined by the data index and not by the id... well it will not return null if the dataIndex == id... is that correct? Is that really a bug? Would be glad if someone could tell me if it is or not (cause someone moved it into this part of the forum)... But I think this should not only occure when there is a paging connected to it... I guess it is a general bug with HeaderColumns and refreshing (whoever triggers the refresh).

I'm not sure if the sortField is the id or the dataindex, but it is used in the source as both (see above it is used as id) and in com.extjs.gxt.ui.client.widget.grid.GridView#updateHeaderSortState there is


int sortColumn = cm.findColumnIndex(state.getSortField());


So to fix this... You can just use the code of the updateHeaderSortState in the refresh... but again if I think about it... the refresh could select the wrong column than... cause there could be two columns (with different ids) but the same dataindex...

Thanks

sven
23 May 2010, 10:13 AM
It got moved because you ignored the bugforum guidelnies once again completly. Posts like this get moved to the help forum.

The code willbe changed for GXT 2.2. GXT 2.2 wont have the problem

Jogilein
23 May 2010, 10:15 AM
So I just tested it with



if (container instanceof Grid) {
Grid grid = (Grid)container;
SortInfo sortInfo = grid.getStore().getSortState();
if (sortInfo != null && sortInfo.getSortField() != null) {
ColumnModel cm = grid.getColumnModel();
updateSortIcon(cm.findColumnIndex(sortInfo.getSortField()), sortInfo.getSortDir());
}
}

and it works this way... I'm still wondering if it wouldn't be better to also add the "SortId" instead of the "SortDataIndex == SortField" cause as mentioned, if you refresh now with the bug fix and there are two columns using the same data index (but different id, e.g. date field with dd.MM.yyyy and a second field with HH:mm) the sort-arrow will move from the second to the first column...

Or maybe all this is already fixed and I didn't find the right post in the forum (I'm really bad with finding the right search words)...

sven
23 May 2010, 10:17 AM
The second issue cannot be fixed at the moment without making big changes. I know about it and will look for GXT3 into it.

Jogilein
23 May 2010, 10:22 AM
It got moved because you ignored the bugforum guidelnies once again completly. Posts like this get moved to the help forum.

I corrected the post (to its current form) after you told me... so I guess you should look before moving or give people at least some time to fix their posts if you tell them that the format is incorrect... or is the current form incorrect again?!

Well the sample is not there... but I guess I don't always have the time to create samples... but I'll try to post better bug reports next time :)...

By the way is the autofill (http://www.extjs.com/forum/showthread.php?99937-CLOSED-setAutoFill%28true%29-and-setForceFit%28false%29-leads-to-quot-growing-quot-last-column) problem solved also so easily? Or is it more work than "just changing one line"? Cause if it is I would appreciate to know the line of code...

Jogilein
23 May 2010, 10:24 AM
The second issue cannot be fixed at the moment without making big changes. I know about it and will look for GXT3 into it.

Thanks for the quick note! I can live with that, right now ;)

diegolovison
15 Feb 2011, 9:18 AM
for this example http://www.sencha.com/examples/explorer.html#localpaging how I can create a local paging using groupview?

thanks