Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-2858 in 3.0.5.
  1. #1
    Ext GWT Premium Member
    Join Date
    Apr 2011
    Posts
    87
    Vote Rating
    0
    subendu is on a distinguished road

      0  

    Question Sorting on tree not working

    Sorting on tree not working


    Hi,
    I am using tree, in that I need to implement the sorting functionality.
    So I have added the sorting tool button in content panel header and after selection of that button I am sorting the tree.
    But its not working.
    See the below code:

    Code:
    import com.demo.gxt.client.resource.TestData;
    import com.demo.gxt.client.resource.images.ExampleImages;
    import com.demo.gxt.client.resource.model.BaseDto;
    import com.demo.gxt.client.resource.model.FolderDto;
    import com.google.gwt.core.client.EntryPoint;
    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.TreeStore;
    import com.sencha.gxt.widget.core.client.ContentPanel;
    import com.sencha.gxt.widget.core.client.button.TextButton;
    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 BasicTreeExample implements IsWidget, EntryPoint {
    
    
    	class KeyProvider implements ModelKeyProvider<BaseDto> {
    		@Override
    		public String getKey(BaseDto item) {
    			return (item instanceof FolderDto ? "f-" : "m-")
    					+ item.getId().toString();
    		}
    	}
    
    
    	@Override
    	public Widget asWidget() {
    		ContentPanel con = new ContentPanel();
    		con.addStyleName("margin-10");
    
    
    		final TreeStore<BaseDto> store = new TreeStore<BaseDto>(
    				new KeyProvider());
    
    
    		FolderDto root = TestData.getMusicRootFolder();
    		for (BaseDto base : root.getChildren()) {
    			store.add(base);
    			if (base instanceof FolderDto) {
    				processFolder(store, (FolderDto) base);
    			}
    		}
    
    
    		final Tree<BaseDto, String> tree = new Tree<BaseDto, String>(store,
    				new ValueProvider<BaseDto, String>() {
    
    
    					@Override
    					public String getValue(BaseDto object) {
    						return object.getName();
    					}
    
    
    					@Override
    					public void setValue(BaseDto object, String value) {
    					}
    
    
    					@Override
    					public String getPath() {
    						return "name";
    					}
    				});
    		con.setWidth(300);
    
    
    		con.add(tree);
    		TextButton sortButton = new TextButton("",
    				ExampleImages.INSTANCE.sortIcon());
    		sortButton.addSelectHandler(new SelectHandler() {
    
    
    			@Override
    			public void onSelect(SelectEvent event) {
    				SortDir sortDir = SortDir.DESC;
    				if (store.getSortInfo().size() > 0) {
    					sortDir = store.getSortInfo().get(0).getDirection();
    					if (sortDir.equals(SortDir.ASC)) {
    						sortDir = SortDir.DESC;
    					} else {
    						sortDir = SortDir.ASC;
    					}
    				}
    				store.applySort(false);
    
    
    			}
    		});
    
    
    		sortButton.setToolTip("Sorting");
    		con.getHeader().addTool(sortButton);
    		return con;
    	}
    
    
    	public void onModuleLoad() {
    		RootPanel.get().add(asWidget());
    	}
    
    
    	private void processFolder(TreeStore<BaseDto> store, FolderDto folder) {
    		for (BaseDto child : folder.getChildren()) {
    			store.add(folder, child);
    			if (child instanceof FolderDto) {
    				processFolder(store, (FolderDto) child);
    			}
    		}
    	}
    }
    Regards,
    Subendu

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Just reading your code without running it. I am not sure what you are trying to do there. You are trying to change the sortDir and calculating the new one, but never using it and then reapplying the same old sorting.

    You might want to try something like this:
    Code:
    store.clearSortInfo();
    store.addSortInfo(new SortInfo(treeValueProvider, sortDir));

  3. #3
    Ext GWT Premium Member
    Join Date
    Apr 2011
    Posts
    87
    Vote Rating
    0
    subendu is on a distinguished road

      0  

    Default


    Hi sven,
    I have added the code you mentioned above still the sorting is not working.
    See the below updated code:
    Code:
    import com.demo.gxt.client.resource.TestData;
    import com.demo.gxt.client.resource.images.ExampleImages;
    import com.demo.gxt.client.resource.model.BaseDto;
    import com.demo.gxt.client.resource.model.FolderDto;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    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.PropertyAccess;
    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.ContentPanel;
    import com.sencha.gxt.widget.core.client.button.TextButton;
    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 BasicTreeExample implements IsWidget, EntryPoint {
    
    
        public interface OrganizationVOProperties extends
                PropertyAccess<BaseDto> {
            ValueProvider<BaseDto, String> name();
        }
    
    
        private static final OrganizationVOProperties organizationVOProperties = GWT
                .create(OrganizationVOProperties.class);
    
    
        class KeyProvider implements ModelKeyProvider<BaseDto> {
            @Override
            public String getKey(BaseDto item) {
                return (item instanceof FolderDto ? "f-" : "m-")
                        + item.getId().toString();
            }
        }
    
    
        @Override
        public Widget asWidget() {
            ContentPanel con = new ContentPanel();
            con.addStyleName("margin-10");
    
    
            final TreeStore<BaseDto> store = new TreeStore<BaseDto>(
                    new KeyProvider());
    
    
            FolderDto root = TestData.getMusicRootFolder();
            for (BaseDto base : root.getChildren()) {
                store.add(base);
                if (base instanceof FolderDto) {
                    processFolder(store, (FolderDto) base);
                }
            }
    
    
            final Tree<BaseDto, String> tree = new Tree<BaseDto, String>(store,
                    organizationVOProperties.name());
            store.addSortInfo(new StoreSortInfo<BaseDto>(
                    organizationVOProperties.name(), SortDir.DESC));
            con.setWidth(300);
    
    
            con.add(tree);
            TextButton sortButton = new TextButton("",
                    ExampleImages.INSTANCE.sortIcon());
            sortButton.addSelectHandler(new SelectHandler() {
    
    
                @Override
                public void onSelect(SelectEvent event) {
                    SortDir sortDir = SortDir.DESC;
                    if (store.getSortInfo().size() > 0) {
                        sortDir = store.getSortInfo().get(0).getDirection();
                        if (sortDir.equals(SortDir.ASC)) {
                            sortDir = SortDir.DESC;
                        } else {
                            sortDir = SortDir.ASC;
                        }
                    }
                    store.clearSortInfo();
                    store.addSortInfo(new StoreSortInfo<BaseDto>(
                            organizationVOProperties.name(), sortDir));
                    store.applySort(false);
    
    
                }
            });
    
    
            sortButton.setToolTip("Sorting");
            con.getHeader().addTool(sortButton);
            return con;
        }
    
    
        public void onModuleLoad() {
            RootPanel.get().add(asWidget());
        }
    
    
        private void processFolder(TreeStore<BaseDto> store, FolderDto folder) {
            for (BaseDto child : folder.getChildren()) {
                store.add(folder, child);
                if (child instanceof FolderDto) {
                    processFolder(store, (FolderDto) child);
                }
            }
        }
    }
    Last edited by subendu; 6 Mar 2013 at 10:00 PM. Reason: wrong name

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    The Tree widget does not seem to listen to the StoreSortEvent. I will move this thread ot the bugs forum. In your code, you can also remove the call to applySort.

  5. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,731
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    We've added sort handlers in the Tree - it should redraw as the TreeGrid already does. This fix is in SVN and the nightly builds, and will be available in the next release.

  6. #6
    Sencha User
    Join Date
    Jul 2011
    Posts
    99
    Vote Rating
    6
    Andreas Samjeske is on a distinguished road

      0  

    Default


    It would be helpful for these kind of tickets to know which releases of GXT are involded:

    - bug has been discovered in release GXT 3.0.x
    - bug has been fixed in release GXT 3.0.y

    Neither is stated here. Now I have to look for release notes. Maybe the reference "EXTGWT-2858" is stated there. If not, I might take the dates of start of this thread and Colins final statement to guess the releases. Thats pain in the ass.
    Again, please state release numbers when dealing with bugs. Not just for this ticket, but in general.

  7. #7
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,731
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Sorry for the confusion on the version, something happened to the header text, and I've reset it. This was fixed in 3.0.5.

    Normally when we fix something internally it should show the version number on the forum post, but there might be a problem with that syncing if this was messed up. I'll look into this further.