Results 1 to 3 of 3

Thread: Tree does not update when sorting is enabled

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member
    Join Date
    Sep 2008
    Posts
    108

    Default Tree does not update when sorting is enabled

    Required Information

    Version(s) of Ext GWT
    3.0.0 GPL

    Browser versions and OS
    (and desktop environment, if applicable)
    • Firefox 12, Windows 7-64bit

    Virtual Machine
    JDK 1.6.X

    Description
    If you create a tree and then sort the store, dynamically added items will not appear.

    Run mode
    Development mode

    Steps to reproduce the problem
    1. Start running in development mode in Eclipse
    2. Open app in browser
    3. Click the "Add" button. Notice that new nodes are added under "AAAA" (whether expanded or collapsed)
    4. Click "Sort" button. This will display a dialog indicating sort is enabled. Notice the tree contents were not updated (root nodes were not sorted).
    5. Click the "Add" button further. Nodes are not added to "AAAA" node. No visible updates
    6. Click the "Clear Sort" button. Now clicking "Add" button will add new nodes (but nodes added during sort are lost) - but still exist in the tree store.
    Expected result
    If sorting is enabled, items should be inserted in sorted order and tree is updated.

    Actual result
    see Description

    Test case
    Code:
    import java.util.Comparator;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.Widget;
    import com.sencha.gxt.core.client.ValueProvider;
    import com.sencha.gxt.data.shared.ModelKeyProvider;
    import com.sencha.gxt.data.shared.SortDir;
    import com.sencha.gxt.data.shared.Store.StoreSortInfo;
    import com.sencha.gxt.data.shared.TreeStore;
    import com.sencha.gxt.widget.core.client.button.ButtonBar;
    import com.sencha.gxt.widget.core.client.button.TextButton;
    import com.sencha.gxt.widget.core.client.container.FlowLayoutContainer;
    import com.sencha.gxt.widget.core.client.container.MarginData;
    import com.sencha.gxt.widget.core.client.event.SelectEvent;
    import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
    import com.sencha.gxt.widget.core.client.tree.Tree;
    public class SortBasicTreeExample implements IsWidget, EntryPoint {
     class TreeItem {
      private int id;
      private String name;
      public TreeItem(int id, String name) {
       this.id = id;
       this.name = name;
      }
      public int getId() {
       return id;
      }
      public String getName() {
       return name;
      }
     }
     class KeyProvider implements ModelKeyProvider<TreeItem> {
      @Override
      public String getKey(TreeItem item) {
       return "" + item.getId();
      }
     }
     
     TreeItem addParent;
     @Override
     public Widget asWidget() {
      final FlowLayoutContainer con = new FlowLayoutContainer();
      con.addStyleName("margin-10");
      final TreeStore<TreeItem> store = new TreeStore<TreeItem>(new KeyProvider());
      buildInitialTree(store);
      final Tree<TreeItem, String> tree = new Tree<TreeItem, String>(store, new ValueProvider<TreeItem, String>() {
       @Override
       public String getValue(TreeItem object) {
        return object.getName();
       }
       @Override
       public void setValue(TreeItem object, String value) {
       }
       @Override
       public String getPath() {
        return "name";
       }
      });
      tree.setBorders(true);
      tree.setWidth(300);
      tree.setHeight(600);
      
      ButtonBar buttonBar = new ButtonBar();
      buttonBar.add(new TextButton("Add", new SelectHandler() {
       int count = 8;
       @Override
       public void onSelect(SelectEvent event) {
        TreeItem newItem = new TreeItem(count++, "another" + count);
        tree.getStore().add(addParent, newItem);
       }
      }));
      buttonBar.add(new TextButton("Sort", new SelectHandler() {
       @Override
       public void onSelect(SelectEvent event) {
        if (tree.getStore().getSortInfo().isEmpty()) {
         tree.getStore().addSortInfo(new StoreSortInfo<TreeItem>(new Comparator<TreeItem>() {
          @Override
          public int compare(TreeItem o1, TreeItem o2) {
           return o1.getName().compareTo(o2.getName());
          }
         }, SortDir.ASC));
         Window.alert("sort added");
        } else {
         SortDir dir = tree.getStore().getSortInfo().get(0).getDirection();
         tree.getStore().getSortInfo().get(0).setDirection((dir == SortDir.DESC) ? SortDir.ASC : SortDir.DESC);
         tree.getStore().applySort(false);
        }
       }
      }));
      
      buttonBar.add(new TextButton("Clear Sort", new SelectHandler() {
       @Override
       public void onSelect(SelectEvent event) {
        tree.getStore().clearSortInfo();
       }
      }));
      buttonBar.setLayoutData(new MarginData(4));
      con.add(buttonBar);
      con.add(tree);
      return con;
     }
     protected void buildInitialTree(final TreeStore<TreeItem> store) {
      TreeItem r1 = new TreeItem(1, "ZZZZ");
      addParent = new TreeItem(2, "AAAA");
      TreeItem r3 = new TreeItem(3, "AAZZ");
      TreeItem r4 = new TreeItem(4, "BBAA");
      store.add(r1);
      store.add(addParent);
      store.add(r3);
      store.add(r4);
      TreeItem c1 = new TreeItem(5, "bbbb");
      TreeItem c2 = new TreeItem(6, "cccc");
      TreeItem c3 = new TreeItem(7, "ccbb");
      store.add(r1, c2);
      store.add(r1, c1);
      store.add(r1, c3);
     }
     public void onModuleLoad() {
      RootPanel.get().add(asWidget());
     }
    }
    Helpful Information


    Debugging already done
    • Have verified the store contents are correct during sorting. The number of roots and children match what is expected. Tree does not reflect content
    Possible fix
    unknown

  2. #2
    Ext GWT Premium Member
    Join Date
    Oct 2007
    Posts
    44

    Default

    I haven't looked closely at this, but it smells like http://www.sencha.com/forum/showthre...tore-is-sorted.

  3. #3
    Ext JS Premium Member
    Join Date
    Sep 2008
    Posts
    108

    Default

    UPDATE (Using GXT 3.0.1 GPL) Interesting.... it is working better (in that nodes are getting inserted in a sorted state) but there is a small issue.... they are getting inserted at sort position -1 (ie. if you have

    10
    11
    12
    13

    And you insert 14 and then 15 it looks like this

    10
    11
    12
    14
    15
    13

    Still it is an improvement (at least they show up!) I'll see if I can track down the offending code in the n-1 insert here and provide a suggested fix/workaround.

    -Jason

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •