Hi Isomorphic,
please see this code (BuiltInDS-based, v9.1p_2014-07-24, FF26 Dev mode (I have a similiar setup in my application, there it is the same way in compiled mode in FF26 and Chrome 36)).
BuiltInDS.java
If you try to re-sort the ListGrid by diet=DESC (by clicking the column or using the context menu), you'll see that this does not work. If you ungroup, sorting by diet is working again.
This seems to be connected to the setSortNormalizer and/or the setGroupValueFunction. If I change either of them to return the diet-string, sorting also works in grouped mode.
Best regards,
Blama
please see this code (BuiltInDS-based, v9.1p_2014-07-24, FF26 Dev mode (I have a similiar setup in my application, there it is the same way in compiled mode in FF26 and Chrome 36)).
BuiltInDS.java
Code:
package com.smartgwt.sample.client; import java.util.LinkedHashMap; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.SortSpecifier; import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.grid.GroupNode; import com.smartgwt.client.widgets.grid.GroupTitleRenderer; import com.smartgwt.client.widgets.grid.GroupValueFunction; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.grid.SortNormalizer; public class BuiltInDS implements EntryPoint { private ListGrid boundList; public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); boundList = new ListGrid(DataSource.get("animals")); boundList.setWidth(1200); boundList.setHeight(600); boundList.setCanMultiSort(true); boundList.setCanSort(true); boundList.setShowFilterEditor(true); boundList.setAutoFetchData(false); ListGridField commonName = new ListGridField("commonName"); ListGridField scientificName = new ListGridField("scientificName"); scientificName.setSortNormalizer(new SortNormalizer() { @Override public Object normalize(ListGridRecord record, String fieldName) { return record.getAttributeAsString(fieldName); } }); ListGridField lifeSpan = new ListGridField("lifeSpan"); ListGridField diet = new ListGridField("diet"); diet.setSortNormalizer(new SortNormalizer() { @Override public Object normalize(ListGridRecord record, String fieldName) { // In order to sort the groups by ID, not name. return getDietMap().get(record.getAttributeAsString("diet")); // return record.getAttributeAsString("diet"); } }); diet.setGroupValueFunction(new GroupValueFunction() { @Override public Object getGroupValue(Object value, ListGridRecord record, ListGridField field, String fieldName, ListGrid grid) { return getDietMap().get(record.getAttributeAsString("diet")); // return record.getAttributeAsString("diet"); } }); diet.setGroupTitleRenderer(new GroupTitleRenderer() { @Override public String getGroupTitle(Object groupValue, GroupNode groupNode, ListGridField field, String fieldName, ListGrid grid) { int i = groupNode.getGroupMembers().length; String groupName = groupNode.getGroupMembers()[0].getAttributeAsString("diet"); return groupName + " (" + i + ((i == 1) ? " Animal)" : " Animals)"); } }); boundList.setGroupByField("diet"); boundList.setFields(commonName, scientificName, lifeSpan, diet); boundList.setSort(new SortSpecifier("diet", SortDirection.ASCENDING)); boundList.fetchData(); boundList.draw(); } public static LinkedHashMap<String, Integer> getDietMap() { LinkedHashMap<String, Integer> vM = new LinkedHashMap<String, Integer>(); vM.put("Carnivore", 1); vM.put("Carnivore (mainly smaller fish)", 2); vM.put("Crustaceans worms and mollusks", 3); vM.put("Fish shrimp eels and squid", 4); vM.put("Fruit and small vertebrates", 5); vM.put("Fruits, Vegetation and Birds eggs", 6); vM.put("Ground dwelling ants/termites", 7); vM.put("Herbivore", 8); vM.put("Insects and Larvae", 10); vM.put("Insects, Fruit, seeds and grasses", 11); vM.put("Insects, small reptiles and mammals", 12); vM.put("Nectar and small insects", 13); vM.put("Omnivore", 14); vM.put("Plants and insects", 15); // Test: If sorting by ID works, this has to be at the start/beginning vM.put("Herbivore (Eucalyptus leaves)", 999); return vM; } }
This seems to be connected to the setSortNormalizer and/or the setGroupValueFunction. If I change either of them to return the diet-string, sorting also works in grouped mode.
Best regards,
Blama
Comment