3.1 TreeGrid.setSort (getSort ()) does not sort
To the best of my knowledge, this worked with 3.0.
No longer works with 3.1d from 2012-09-23.
With 3.1:
1. setSort (getSort ()) does not wort
2. setSort (new SortSpecifier[] {...}) does sort
3. setSort (deep clone of getSort ()) does sort
Version
GWT version: 2.3.0
SmartGWT version: 3.1d
SmartGWT buildDate: Sun Sep 23 00:02:00 PDT 2012
SmartGWT major-minor-patch: 3-1d-0
SmartGWT SC: SNAPSHOT_v8.3d_2012-09-23
Browser: FireFox 6.0.2
Dev console
Sample code:
To the best of my knowledge, this worked with 3.0.
No longer works with 3.1d from 2012-09-23.
With 3.1:
1. setSort (getSort ()) does not wort
2. setSort (new SortSpecifier[] {...}) does sort
3. setSort (deep clone of getSort ()) does sort
Version
GWT version: 2.3.0
SmartGWT version: 3.1d
SmartGWT buildDate: Sun Sep 23 00:02:00 PDT 2012
SmartGWT major-minor-patch: 3-1d-0
SmartGWT SC: SNAPSHOT_v8.3d_2012-09-23
Browser: FireFox 6.0.2
Dev console
Code:
09:50:01.503:INFO:Log:initialized 09:50:01.530:WARN:Log:NOTE: Firebug is enabled. Firebug greatly slows the performance of applications that make heavy use of JavaScript. Isomorphic highly recommends Firebug for troubleshooting, but Firebug and other development tools should be disabled when assessing the real-world performance of SmartClient applications. 09:50:08.071:INFO:Log:isc.Page is loaded
Code:
import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.tree.TreeGrid; import com.smartgwt.client.widgets.tree.Tree; import com.smartgwt.client.widgets.tree.TreeGridField; import com.smartgwt.client.widgets.tree.TreeNode; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.types.TreeModelType; import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.data.SortSpecifier; import com.smartgwt.client.Version; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; public class TestTreeGridSort implements EntryPoint { // my attributes int nextNodeId = 1; /** * The EntryPoint interface */ public void onModuleLoad () { // test SC.showConsole (); GWT.log ("GWT version: " + GWT.getVersion ()); GWT.log ("SmartGWT version: " + Version.getVersion ()); GWT.log ("SmartGWT buildDate: " + Version.getBuildDate ()); GWT.log ("SmartGWT major-minor-patch: " + Version.getMajor () + "-" + Version.getMinor () + "-" + Version.getPatch ()); GWT.log ("SmartGWT SC: " + Version.getSCVersionNumber ()); // configure Tree final Tree tree = new Tree (); tree.setModelType (TreeModelType.PARENT); tree.setNameProperty ("name"); tree.setIdField ("nodeId"); tree.setParentIdField ("parentNodeId"); tree.setShowRoot (true); // configure TreeGrid final TreeGridField nameField = new TreeGridField ("name", "Name", 200); final TreeGrid treeGrid = new TreeGrid (); treeGrid.setWidth (300); treeGrid.setHeight (200); treeGrid.setSeparateFolders (true); treeGrid.setSortFoldersBeforeLeaves (true); treeGrid.setSortField ("name"); treeGrid.setSortDirection (SortDirection.ASCENDING); treeGrid.setFields (nameField); treeGrid.setData (tree); // add a few nodes, folders addTreeNode (tree, true, "A"); addTreeNode (tree, false, "B"); addTreeNode (tree, true, "C"); addTreeNode (tree, false, "D"); addTreeNode (tree, true, "E"); addTreeNode (tree, false, "F"); addTreeNode (tree, true, "G"); // call setSort (getSort ()). this worked with 3.0 final IButton setSortGetSortButton = new IButton (); setSortGetSortButton.setAutoFit (true); setSortGetSortButton.setTitle ("setSort (getSort ())"); setSortGetSortButton.addClickHandler (new ClickHandler () { public void onClick (final ClickEvent event) { final SortSpecifier [] sortSpecifierArray = treeGrid.getSort (); GWT.log ("sortSpecifierArray [0]: " + sortSpecifierArray[0].getField () + " / " + sortSpecifierArray[0].getSortDirection ().getValue ()); treeGrid.setSort (sortSpecifierArray); } }); // call setSort (new SortSpecifier[] ()). final IButton setSortWithSortSpecifierButton = new IButton (); setSortWithSortSpecifierButton.setAutoFit (true); setSortWithSortSpecifierButton.setTitle ("setSort (SortSpecifier[])"); setSortWithSortSpecifierButton.addClickHandler (new ClickHandler () { public void onClick (final ClickEvent event) { final SortSpecifier [] sortSpecifierArray = new SortSpecifier [] { new SortSpecifier ("name", SortDirection.ASCENDING) }; GWT.log ("sortSpecifierArray [0]: " + sortSpecifierArray[0].getField () + " / " + sortSpecifierArray[0].getSortDirection ().getValue ()); treeGrid.setSort (sortSpecifierArray); // treeGrid.setSort (new SortSpecifier [] { new SortSpecifier ("name", SortDirection.ASCENDING) }); } }); // call setSort (rebuild SortSpecifier[] from getSort ()) final IButton resortButton = new IButton (); resortButton.setAutoFit (true); resortButton.setTitle ("resort ()"); resortButton.addClickHandler (new ClickHandler () { public void onClick (final ClickEvent event) { resort (treeGrid); } }); // layout final VLayout layout = new VLayout (); layout.addMember (treeGrid); layout.addMember (setSortGetSortButton); layout.addMember (setSortWithSortSpecifierButton); layout.addMember (resortButton); layout.show (); } /** * Helper: uniformely adds the given TreeNode * @param tree * @param isFolder * @param name */ private void addTreeNode ( final Tree tree, final boolean isFolder, final String name) { nextNodeId ++; final TreeNode treeNode = new TreeNode (); treeNode.setAttribute ("nodeId", nextNodeId); treeNode.setAttribute ("parentNodeId", 1); // hard-coded treeNode.setAttribute ("name", name); treeNode.setIsFolder (isFolder); final TreeNode rootTreeNode = tree.getRoot (); tree.add (treeNode, rootTreeNode); } /** * Resorts this TreeGrid based on the current sorting specifiers */ public static void resort (final TreeGrid treeGrid) { // get the current config final SortSpecifier[] sortSpecifierArray = treeGrid.getSort (); if (sortSpecifierArray == null) { return; } // rebuild the SortSpecifier array final SortSpecifier[] sortSpecifierArray2 = new SortSpecifier[sortSpecifierArray.length]; int index = -1; for (final SortSpecifier sortSpecifier : sortSpecifierArray) { index ++; sortSpecifierArray2 [index] = new SortSpecifier (sortSpecifier.getField (), sortSpecifier.getSortDirection ()); } // sort with that treeGrid.setSort (sortSpecifierArray2); } }
Comment