Results 1 to 4 of 4

Thread: gxt3 TreeGrid Filter

  1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    27
    Vote Rating
    1
      0  

    Default gxt3 TreeGrid Filter

    hello everybody
    i have a trouble about the add the filter on the TreeGrid
    i need your help.
    thanks !


    the treegrid like this image(in this image ,i click the node 1,the node 2 show, click the node 2 the node 4 show , 1,2,3,4 is the ID get it from the databse)
    1.jpg



    if i input the value is 1 or 2 or 3 into the

    StoreFilterField
    the treeGrid can show normal
    like this image:
    2.jpg

    if i input the value is 4 into the

    StoreFilterField
    it like this:
    it is waiting......
    3.jpg

    who can help me ?
    why like this?

    the return json data like this:
    {"records":[{"id":2,"name":"two","desc":"two","parent":true,"permission":false,"state":1}]}
    why filter the id is 4,and the id is 1 can show ,and the id is 2 can search from the databse and return as the jsondata,but the id is 4(who input into the

    StoreFilterField can't return as the jsondata.

    http://stackoverflow.com/questions/3...reegrid-filter

    my code :

    Code:
    package com.sa.permissions.client.role;
    
    import com.google.gwt.cell.client.AbstractCell;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.editor.client.Editor;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.http.client.Request;
    import com.google.gwt.http.client.RequestBuilder;
    import com.google.gwt.http.client.RequestCallback;
    import com.google.gwt.http.client.Response;
    import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
    import com.google.gwt.safehtml.shared.UriUtils;
    import com.google.gwt.user.client.ui.Image;
    import com.google.gwt.user.client.ui.Widget;
    import com.google.web.bindery.autobean.shared.AutoBean;
    import com.google.web.bindery.autobean.shared.AutoBeanFactory;
    import com.sencha.gxt.core.client.IdentityValueProvider;
    import com.sencha.gxt.core.client.Style;
    import com.sencha.gxt.core.client.ValueProvider;
    import com.sencha.gxt.core.client.dom.ScrollSupport;
    import com.sencha.gxt.core.client.util.IconHelper;
    import com.sencha.gxt.data.client.loader.HttpProxy;
    import com.sencha.gxt.data.client.writer.UrlEncodingWriter;
    import com.sencha.gxt.data.shared.ModelKeyProvider;
    import com.sencha.gxt.data.shared.PropertyAccess;
    import com.sencha.gxt.data.shared.Store;
    import com.sencha.gxt.data.shared.TreeStore;
    import com.sencha.gxt.data.shared.loader.ChildTreeStoreBinding;
    import com.sencha.gxt.data.shared.loader.JsonReader;
    import com.sencha.gxt.data.shared.loader.TreeLoader;
    import com.sencha.gxt.desktop.client.extend.*;
    import com.sencha.gxt.theme.base.client.info.InfoDefaultAppearance;
    import com.sencha.gxt.widget.core.client.Dialog;
    import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
    import com.sencha.gxt.widget.core.client.box.ConfirmMessageBox;
    import com.sencha.gxt.widget.core.client.button.TextButton;
    import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer;
    import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
    import com.sencha.gxt.widget.core.client.event.DialogHideEvent;
    import com.sencha.gxt.widget.core.client.event.RowDoubleClickEvent;
    import com.sencha.gxt.widget.core.client.event.SelectEvent;
    import com.sencha.gxt.widget.core.client.form.StoreFilterField;
    import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
    import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
    import com.sencha.gxt.widget.core.client.grid.ColumnModel;
    import com.sencha.gxt.widget.core.client.info.Info;
    import com.sencha.gxt.widget.core.client.toolbar.SeparatorToolItem;
    import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
    import com.sencha.gxt.widget.core.client.treegrid.TreeGrid;
    
    import java.util.*;
    
    /*import org.timepedia.exporter.client.Export;
    import org.timepedia.exporter.client.Exportable;*/
    
    public class RoleListWindow extends MyWindow{
        private final RoleListWindow myself = this;
        private TreeLoader<JsonData> loader;
        private TreeStore<JsonData> store;
        private JsonDataProperties prop;
        private ColumnModel<JsonData> columnModel;
        private TreeGrid<JsonData> grid;
        private ToolBar toolBar;
        private AddRoleWindow addRoleWindow;
        private final CheckBoxSelectionModel<JsonData> sm;
        private SelectedHandler selectedHandler;
    
        private boolean multipleSelect;
    
        private boolean selected;
    
    
        private StoreFilterField<JsonData> filterField;
        private TextButton submit;
    
        @Override
        protected void onLoad() {
            super.onLoad();
        }
    
        @Override
        public void onShow() {
            getTreeLoader().load();
            sm.deselectAll();
            super.onShow();
        }
    
    
        @Override
        public String getAppName() {
            return "role list";
        }
    
        private final String URL_OF_ROLE_LIST = Const.SERVER .concat( "role!showList.do");
        private final String URL_OF_ROLE_DEL = Const.SERVER .concat("role!showdel.do");
    
        public RoleListWindow() {
            sm = new CheckBoxSelectionModel<JsonData>(new IdentityValueProvider<JsonData>());
            init();
        }
    
        public boolean isSelected() {
            return selected;
        }
    
        public void setSelected(boolean selected) {
            if (selected && selected != isSelected()) {
                this.addButton(getSubmit());
                this.setButtonAlign(BoxLayoutContainer.BoxLayoutPack.CENTER);
               
            }
            this.selected = selected;
        }
    
        public JsonDataProperties getProp() {
            if (this.prop == null)
                this.prop = GWT.create(JsonDataProperties.class);
            return this.prop;
        }
    
        public void setProp(JsonDataProperties prop) {
            this.prop = prop;
        }
    
        public TreeStore<JsonData> getStore() {
            if (this.store == null) {
                this.store = new TreeStore<JsonData>(new ModelKeyProvider<JsonData>() {
                    @Override
                    public String getKey(JsonData item) {
                        return item.getId().toString();
                    }
                });
            }
            return this.store;
        }
    
        public TreeLoader<JsonData> getLoader() {
            return loader;
        }
    
        public void setLoader(TreeLoader<JsonData> loader) {
            this.loader = loader;
        }
    
        public SelectedHandler getSelectedHandler() {
            return selectedHandler;
        }
    
        public void setSelectedHandler(SelectedHandler selectedHandler) {
            this.selectedHandler = selectedHandler;
        }
    
        public boolean isMultipleSelect() {
            return multipleSelect;
        }
    
        public void setMultipleSelect(boolean multipleSelect) {
            if (multipleSelect)
                sm.setSelectionMode(Style.SelectionMode.MULTI);
            else
                sm.setSelectionMode(Style.SelectionMode.SINGLE);
            getGrid().setSelectionModel(sm);
            this.multipleSelect = multipleSelect;
        }
    
    
        public StoreFilterField<JsonData> getFilterField() {
            if (null == this.filterField) {
                filterField = new StoreFilterField<JsonData>() {
                    @Override
                    protected boolean doSelect(Store<JsonData> jsonUserDataStore, JsonData parent, JsonData item, String filter) {
                      /*  new AlertMessageBox("","item="+item.getName()+" parent="+(null!=parent?parent.getName():"null")).show();*/
                        return (null!=item&&item.getId()!=null&&item.getId().equals(JsonUtil.parseLong(filter.trim(),0L)) );
                    }
                };
                filterField.setPixelSize(fieldwidth, fieldheight);
                filterField.bind(getStore());
                filterField.setEmptyText("input filter");
            }
            return filterField;
        }
    
        public void setFilterField(StoreFilterField<JsonData> filterField) {
            this.filterField = filterField;
        }
    
        public TextButton getSubmit() {
            if (this.submit == null) {
                submit = new TextButton("submit");
                submit.addSelectHandler(new SelectEvent.SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        if (null != getSelectedHandler()) {
                            List<JsonData> list = getGrid().getSelectionModel().getSelection();
                            if (null != list && !list.isEmpty()) {
                                Iterator<JsonData> it = list.iterator();
    
                                Map<Long, String> map = new HashMap<Long, String>();
                                while (it.hasNext()) {
                                    JsonData jsonData = it.next();
                                    map.put(jsonData.getId(), jsonData.getName());
                                    selectedHandler.setReturnValue(map);
                                }
                            }
                        }
                        myself.hide();
                    }
                });
            }
            return submit;
        }
        private ColumnModel<JsonData> getColumnModel() {
            if (this.columnModel == null) {
                ColumnConfig<JsonData, Long> id = new ColumnConfig<JsonData, Long>(getProp().id(), 20, "ID");
                final ColumnConfig<JsonData, String> appName = new ColumnConfig<JsonData, String>(getProp().name(), 100, "name");
                appName.setCell(new AbstractCell<String>() {
                    @Override
                    public void render(Context context, String value, SafeHtmlBuilder sb) {
                        if (JsonUtil.isNotEmpty(value)) {
                            String key = "<span ".concat("  title='").concat(value).concat("'").concat(">").concat(JsonUtil.cutStr(value,50)).concat("</span>");
                            sb.appendHtmlConstant(key);
                        }
                    }
                });
                final ColumnConfig<JsonData, String> desc = new ColumnConfig<JsonData, String>(getProp().desc(), 50, "desc");
                desc.setCell(new AbstractCell<String>() {
                    @Override
                    public void render(Context context, String value, SafeHtmlBuilder sb) {
                        if (JsonUtil.isNotEmpty(value)) {
                            String key = "<span ".concat("  title='").concat(value).concat("'").concat(">").concat(JsonUtil.cutStr(value,10)).concat("</span>");
                            sb.appendHtmlConstant(key);
                        }
                    }
                });
    
                ColumnConfig columnConfig=sm.getColumn();
                columnConfig.setCell(new AbstractCell() {
                                         @Override
                                         public void render(Context context, Object value, SafeHtmlBuilder sb) {
                                            
                                             if((((JsonData) value).getParent()||((JsonData) value).getPermission()))
                                                 sm.getAppearance().renderCellCheckBox(context, value, sb);
                                         }
                                     }
                );
    
    
                List<ColumnConfig<JsonData, ?>> l = new ArrayList<ColumnConfig<JsonData, ?>>();
                l.add(columnConfig);
    
                l.add(id);
                l.add(appName);
                l.add(desc);
                this.columnModel = new ColumnModel<JsonData>(l);
            }
            return this.columnModel;
    
        }
    
        private TreeLoader<JsonData> getTreeLoader() {
            if (this.loader == null) {
                JsonGridAutoBeanFactory factory = GWT.create(JsonGridAutoBeanFactory.class);
                DataRecordJsonReader reader = new DataRecordJsonReader(factory, JSonDataRecordResult.class);
                RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, URL_OF_ROLE_LIST);
    
                HttpProxy<JsonData> jsonProxy = new HttpProxy<JsonData>(requestBuilder) { };
                jsonProxy.setWriter(new UrlEncodingWriter<JsonData>(factory, JsonData.class));
                this.loader = new TreeLoader<JsonData>(jsonProxy, reader) {
                    @Override
                    public boolean hasChildren(JsonData parent) {
                        return parent.getParent();
                    }
                };
                this.loader.addLoadHandler(new ChildTreeStoreBinding<JsonData>(getStore()));
            }
    
            return this.loader;
    
        }
    
    
        private TreeGrid<JsonData> getGrid() {
            if (this.grid == null) {
                ColumnModel<JsonData> columnModel = getColumnModel();
                this.grid = new TreeGrid<JsonData>(getStore(), columnModel, columnModel.getColumns().get(1));
                this.grid.addRowDoubleClickHandler(new RowDoubleClickEvent.RowDoubleClickHandler() {
                    @Override
                    public void onRowDoubleClick(RowDoubleClickEvent event) {
                        JsonData data = (JsonData) event.getSource().getSelectionModel().getSelectedItem();
                        AddRoleWindow editRoleWindow = getAddRoleWindow();
                        editRoleWindow.setAddorEdit(false);/*
                        editRoleWindow.setRoleIdValue(data.getId());*/
                        editRoleWindow.setLoader(getTreeLoader());
                        editRoleWindow.setStateValue(data.getState());
                        editRoleWindow.getRoleName().setValue(data.getName());
                        editRoleWindow.getRoleDesc().setValue(data.getDesc());
                        editRoleWindow.show();
                    }
                });
                this.grid.setBorders(true);
                this.grid.setTreeLoader(getTreeLoader());
                this.grid.getView().setStripeRows(true);
                this.grid.getView().setColumnLines(true);
                this.grid.getView().setTrackMouseOver(false);
                this.grid.getView().setForceFit(true);
                this.grid.getView().setAutoFill(true);
                this.grid.getView().setAutoExpandColumn(columnModel.getColumns().get(1));
                sm.setSelectionMode(Style.SelectionMode.MULTI);
                /* sm.setSelectionMode(isMultipleSelect()?Style.SelectionMode.MULTI:Style.SelectionMode.SINGLE);*/
                this.grid.setSelectionModel(sm);
            }
            return this.grid;
        }
    
        private ToolBar getToolBar() {
            if (null == this.toolBar) {
                this.toolBar = new ToolBar();
                Image add = getImage("app_add","add",getImgpix(),getImgpix());
                
                this.toolBar.add(add);
                
               toolBar.add(getFilterField());
            }
            return this.toolBar;
        }
    
        private AddRoleWindow getAddRoleWindow() {
            if (this.addRoleWindow == null) {
                this.addRoleWindow = (AddRoleWindow) MoudleFactory.moudleMap.get(AddRoleWindow.class.getName());
                this.addRoleWindow = null == this.addRoleWindow ? new AddRoleWindow() : this.addRoleWindow;
            }
            return this.addRoleWindow;
        }
    
        private void init() {
            VerticalLayoutContainer  con = new VerticalLayoutContainer ();
            con.add(getToolBar(), new VerticalLayoutContainer.VerticalLayoutData(1, -1));
            con.add(getGrid(), new VerticalLayoutContainer.VerticalLayoutData(1, 1));
    
            this.setPixelSize(defaultWidth, defaultHeight);
            con.setScrollMode(ScrollSupport.ScrollMode.AUTO);
    
            this.add(con);
            if (isSelected()) {
                this.addButton(getSubmit());
                this.setButtonAlign(BoxLayoutContainer.BoxLayoutPack.CENTER);
                this.setHeadingText("role select");
            } else
                this.setHeadingText("role");
            this.setBodyBorder(true);
            this.setMinimizable(true);
            this.setMaximizable(true);
    
    
        }
    
    
        class DataRecordJsonReader extends JsonReader<List<JsonData>, JSonDataRecordResult> {
            public DataRecordJsonReader(AutoBeanFactory factory, Class<JSonDataRecordResult> rootBeanType) {
                super(factory, rootBeanType);
            }
    
            @Override
            protected List<JsonData> createReturnData(Object loadConfig, JSonDataRecordResult records) {
                List<JsonData> r = records.getRecords();
                return r;
            }
    
        }
    
        interface JsonData {
            public Long getId();
            public String getName();
            public String getDesc();
            public boolean getParent();
            public boolean getPermission();
            public Integer getState();
    
    
        }
    
        class KeyProvider implements ModelKeyProvider<JsonData> {
    
            @Override
            public String getKey(JsonData item) {
                return item.getId().toString();
            }
        }
    
        interface JSonDataRecordResult {
            public List<JsonData> getRecords();
    
        }
    
        interface JsonGridAutoBeanFactory extends AutoBeanFactory {
            AutoBean<JSonDataRecordResult> items();
        }
    
        interface JsonDataProperties extends PropertyAccess<JsonData> {
            @Editor.Path("id")
            ModelKeyProvider<JsonData> key();
            ValueProvider<JsonData, Long> id();
            ValueProvider<JsonData, String> name();
            ValueProvider<JsonData, String> desc();
            ValueProvider<JsonData, Boolean> parent();
            ValueProvider<JsonData, Boolean> permission();
            ValueProvider<JsonData, Integer> state();
        }
    
    
    
    }
    Last edited by sanbenwu; 5 Dec 2015 at 10:32 PM. Reason: change

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Location
    Germany
    Posts
    223
    Vote Rating
    24
      0  

    Default

    To make it easier for others to help you
    - you should provide some more info (GWT version, GXT version, mode, Browser, etc.)
    - you should make your code easily readable using [ CODE ][ /CODE ] tags.

    And at least over here your screenshots don't show up.

  3. #3
    Sencha - Support Team
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,010
    Vote Rating
    27
      0  

    Default

    What you're running into is more a bug than it is design. The problem is there is a loader and each subtree asyncly loads. Since the subtrees aren't loaded at the time of filtering there isn't a way to filter what is not there. But even if they were loaded, there is a bug that clobbers the filter. So instead of using a remote loader and data proxy on the tree store you simulate it.

    I've added an inital load path and expand handlers to load. This will only filter the local store, that data that is loaded. To do filtering with remote data, it really should filter and retrieve and bring back those nodes to the local store. This could do that with a bit more work, but I haven't mocked it here.
    Code:
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;
    
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.Scheduler;
    import com.google.gwt.core.client.Scheduler.ScheduledCommand;
    import com.google.gwt.resources.client.ImageResource;
    import com.google.gwt.user.client.Timer;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.Widget;
    import com.sencha.gxt.core.client.GXT;
    import com.sencha.gxt.core.client.ValueProvider;
    import com.sencha.gxt.data.shared.ModelKeyProvider;
    import com.sencha.gxt.data.shared.TreeStore;
    import com.sencha.gxt.data.shared.event.StoreFilterEvent;
    import com.sencha.gxt.data.shared.loader.FilterConfig;
    import com.sencha.gxt.state.client.CookieProvider;
    import com.sencha.gxt.state.client.StateManager;
    import com.sencha.gxt.test.client.treegrid_filtering.TreeGridFilters;
    import com.sencha.gxt.widget.core.client.container.Viewport;
    import com.sencha.gxt.widget.core.client.event.ActivateEvent;
    import com.sencha.gxt.widget.core.client.event.ActivateEvent.ActivateHandler;
    import com.sencha.gxt.widget.core.client.event.ExpandItemEvent;
    import com.sencha.gxt.widget.core.client.event.ExpandItemEvent.ExpandItemHandler;
    import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
    import com.sencha.gxt.widget.core.client.grid.ColumnModel;
    import com.sencha.gxt.widget.core.client.grid.filters.Filter;
    import com.sencha.gxt.widget.core.client.grid.filters.StringFilter;
    import com.sencha.gxt.widget.core.client.tree.Tree.TreeNode;
    import com.sencha.gxt.widget.core.client.treegrid.TreeGrid;
    import com.sencha.gxt.widget.core.client.treegrid.TreeGridView;
    
    
    public class TreeWithSimulatedAsyncLoad2 implements EntryPoint {
      /**
       * Provide access to the loading icon
       */
      public class TreeGridViewExt<M> extends TreeGridView<M> {
        /**
         * Display the loading icon
         */
        // ------ Turn on/off loading
        public void setLoading(M m, boolean turnon) {
          TreeNode<M> node = findNode(m);
          if (turnon) {
            onIconStyleChange(node, tree.getTreeAppearance().loadingIcon());
          } else {
            // ----- Added a cast for TreeGrid method
            onIconStyleChange(node, treeGrid.calculateIconStyle((Data) m));
          }
        }
      }
    
    
      // ----- Added TreeGridExt for access to calculating style for joint
      public class TreeGridExt extends TreeGrid<Data> {
        public TreeGridExt(TreeStore<Data> store, ColumnModel<Data> cm, ColumnConfig<Data, ?> treeColumn) {
          super(store, cm, treeColumn);
        }
    
    
        // ------ Expose calculate icon style for TreeGridView
        @Override
        public ImageResource calculateIconStyle(Data model) {
          return super.calculateIconStyle(model);
        }
      }
    
    
      private TreeStore<Data> treeStore;
      private TreeGridViewExt<Data> treeGridView;
      private TreeGridExt treeGrid;
      private KeyProvider keyProvider;
    
    
      /**
       * Mark which parents have been loaded. This will determine if the data has
       * already been loaded.
       */
      private Set<Data> hasBeenLoadedList = new HashSet<Data>();
      private TreeGridStateHandler<Data> stateManager;
    
    
      public Widget asWidget() {
        keyProvider = new KeyProvider();
        treeStore = new TreeStore<Data>(keyProvider);
    
    
        ValueProvider<Data, String> nameValueProvider = new ValueProvider<Data, String>() {
          @Override
          public String getValue(Data object) {
            return object.getName();
          }
    
    
          @Override
          public void setValue(Data object, String value) {
          }
    
    
          @Override
          public String getPath() {
            return "name";
          }
        };
    
    
        ColumnConfig<Data, String> nameColumn = new ColumnConfig<Data, String>(nameValueProvider);
        nameColumn.setHeader("Name");
        nameColumn.setWidth(200);
    
    
        List<ColumnConfig<Data, ?>> columns = new ArrayList<ColumnConfig<Data, ?>>();
        columns.add(nameColumn);
    
    
        ColumnModel<Data> columnModel = new ColumnModel<Data>(columns);
    
    
        treeGridView = new TreeGridViewExt<Data>();
    
    
        treeGrid = new TreeGridExt(treeStore, columnModel, nameColumn) {
          @Override
          protected boolean hasChildren(Data model) {
            // 2. ~~~~~~~ Determine if the node has children, and if so, means its a
            // folder with children
            // Note: this could be a boolean value to signify the node is a folder
            // with children
            return model.getChildCount() > 0;
          }
    
    
          @Override
          protected void onFilter(StoreFilterEvent<Data> se) {
            super.onFilter(se);
    
    
            // @@@@ Restore the expanded state to the nodes
            Scheduler.get().scheduleFinally(new ScheduledCommand() {
              @Override
              public void execute() {
                stateManager.loadState();
              }
            });
          }
        };
        treeGrid.setView(treeGridView);
        treeGrid.setExpandOnFilter(false);
        treeGrid.addExpandHandler(new ExpandItemHandler<Data>() {
          @Override
          public void onExpand(ExpandItemEvent<Data> event) {
            // ~~~~~~ 3. load more children on expansion
            Data parent = event.getItem();
            rpcRequestToGetChildNodes(parent);
          }
        });
    
    
        StringFilter<Data> nameFilter = new StringFilter<Data>(nameValueProvider);
        nameFilter.addActivateHandler(new ActivateHandler<Filter<Data, ?>>() {
          @Override
          public void onActivate(ActivateEvent<Filter<Data, ?>> event) {
            // Fetch all nodes that match the filter
            System.out.println("activated name filter - lets fetch all the nodes that");
    
    
            rpcRequestToGetFilteredNodes(event.getItem().getFilterConfig());
          }
        });
    
    
        TreeGridFilters<Data> treeGridFilters = new TreeGridFilters<Data>();
        treeGridFilters.initPlugin(treeGrid);
        treeGridFilters.setLocal(true);
        treeGridFilters.addFilter(nameFilter);
    
    
        // ~~~~~ 1. initial load - load the root nodes
        rpcRequestToGetRootNodes();
    
    
        // @@@@ set the stateful properties for teh StateManager
        treeGrid.setStateful(true);
        treeGrid.setStateId("gridExample");
    
    
        // @@@@ Stage manager, load previous state
        stateManager = new TreeGridStateHandler<Data>(treeGrid);
        // TODO restore saved state on initial load
        // stateManager.loadState();
    
    
        return treeGrid;
      }
    
    
      /**
       * Suggestion: Go fetch all the nodes form the server that match the server,
       * include their parents and on return add them to the tree store.
       */
      protected void rpcRequestToGetFilteredNodes(List<FilterConfig> filterConfig) {
        FilterConfig filter = filterConfig.get(0);
        String filterValue = filter.getValue();
        System.out.println("filterValue=" + filterValue);
      }
    
    
      /**
       * Pretend RPC call to get data from server
       */
      private void rpcRequestToGetRootNodes() {
        // Pretend this is an RPC call for initial load.
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
          @Override
          public void execute() {
            // RPC call to get root nodes
            List<Data> rootNodes = getRpcRequestWithDatas(null);
            // On RPC return add to treestore
            treeStore.add(rootNodes);
          }
        });
      }
    
    
      /**
       * Pretend RPC call to get data server and add it to treestore.
       * 
       * Note: this won't replace child if it's already loaded.
       * 
       * @param parent
       */
      private void rpcRequestToGetChildNodes(final Data parent) {
        if (hasBeenLoadedList.contains(parent)) {
          // only load the data once
          System.out.println("Skipping loading data for parent=" + parent);
          return;
        }
    
    
        // display the loading icon
        // ---- Turn on loading
        treeGridView.setLoading(parent, true);
    
    
        // Pretend this is an RPC call for initial load.
        Timer timerLikeRpc = new Timer() {
          @Override
          public void run() {
            // ---- Turn off loading
            treeGridView.setLoading(parent, false);
            
            // RPC call to get root nodes
            List<Data> childNodes = getRpcRequestWithDatas(parent);
            // On RPC return, add the nodes to the treestore
            // Since expanding can happen more than once, check to see if the node
            // exists already
            for (Data child : childNodes) {
              // check to see if the model has been already been loaded
              // (TODO if node changes to different branch, then it needs to removed
              // and added)
              Data dataExists = treeStore.findModelWithKey(keyProvider.getKey(child));
              if (dataExists == null) {
                treeStore.add(parent, child);
                hasBeenLoadedList.add(parent);
              }
            }
          }
        };
        timerLikeRpc.schedule(2000);
      }
    
    
      /**
       * Server request goes to this
       */
      private List<Data> getRpcRequestWithDatas(Data parent) {
        List<Data> list = new ArrayList<Data>();
    
    
        if (parent == null) {
          Data a = new Data("0", "A", 0);
          a.setChildCount(5);
    
    
          Data b = new Data("1", "B", 1);
          b.setChildCount(4);
    
    
          Data c = new Data("2", "C", 2);
          c.setChildCount(3);
    
    
          list.add(a);
          list.add(b);
          list.add(c);
    
    
        } else {
          String k = parent.getName();
    
    
          int c = 0;
          if (k.contains("A")) {
            c = 5;
          } else if (k.contains("B")) {
            c = 4;
          } else {
            c = 3;
          }
    
    
          for (int i = 0; i < c; i++) {
            String id = parent.getId() + " : " + i;
    
    
            Data d = new Data(id, k + "+" + i, 3);
            d.setChildCount(0);
            list.add(d);
    
    
            System.out.println("id=" + id + " name=" + d.getName());
    
    
            // first child has some children
            if (i == 0 && d.getName().equals("A+0")) {
              d.setChildCount(5);
            }
          }
        }
    
    
        return list;
      }
    
    
      class KeyProvider implements ModelKeyProvider<Data> {
        @Override
        public String getKey(Data item) {
          return item.getId().toString();
        }
      }
    
    
      public class Data implements Serializable {
        private String id;
        private String name;
        private int value;
        /**
         * Record if this is a folder node and it has children it could load This
         * could be a boolean value too. See TreeGrid.hasChildren.
         */
        private int childCount;
    
    
        protected Data() {
        }
    
    
        public Data(String id, String name, int value) {
          this.id = id;
          this.name = name;
          this.value = value;
        }
    
    
        public String getId() {
          return id;
        }
    
    
        public void setId(String id) {
          this.id = id;
        }
    
    
        public String getName() {
          return name;
        }
    
    
        public void setName(String name) {
          this.name = name;
        }
    
    
        public int getValue() {
          return value;
        }
    
    
        public void setId(int value) {
          this.value = value;
        }
    
    
        @Override
        public String toString() {
          return name;
        }
    
    
        public void setChildCount(int childCount) {
          this.childCount = childCount;
        }
    
    
        /**
         * This tells tree if it's a folder or not
         */
        public int getChildCount() {
          return childCount;
        }
    
    
      }
    
    
      @Override
      public void onModuleLoad() {
        // @@@@ State manager, initialize the state options
        StateManager.get().setProvider(new CookieProvider("/", null, null, GXT.isSecure()));
    
    
        Viewport viewport = new Viewport();
        viewport.add(asWidget());
        RootPanel.get().add(viewport);
      }
    
    
    }
    Does that help?
    Thanks,
    Brandon
    GXT Support Engineer

    ~ Sencha Conference ~
    https://www.senchacon.com/

    ~ GXT Guides ~
    http://docs.sencha.com/gxt/4.x/

    ~ Support Tickets ~
    https://support.sencha.com/index.php

    ~ Tips and Announcements Community ~
    https://plus.google.com/communities/110447085143928405373

    ~ Training ~
    Get on the Fast Track with Sencha Training http://sencha.com/training

  4. #4
    Sencha User
    Join Date
    Mar 2017
    Location
    Pune
    Posts
    2
    Vote Rating
    0
      0  

    Default

    How to insert nodes from multiple trees into one particular row?

Similar Threads

  1. GXT3.1.0 TreeGrid Node was not found error
    By elisma in forum Sencha GXT Discussion
    Replies: 1
    Last Post: 16 Aug 2016, 1:51 AM
  2. Treegrid Filter
    By bluenile in forum Ext: Discussion
    Replies: 3
    Last Post: 8 Jul 2014, 12:25 PM
  3. how to get the child for the gxt3 TreeGrid
    By sanbenwu in forum Sencha GXT Q&A
    Replies: 5
    Last Post: 14 Oct 2013, 1:18 AM
  4. How to filter an Asynch TreeGrid ?
    By Drenoux in forum Ext GWT: Discussion
    Replies: 3
    Last Post: 8 Dec 2011, 4:44 AM
  5. Async TreeGrid + Filter
    By sarsipius in forum Ext GWT: Discussion
    Replies: 3
    Last Post: 28 Jul 2010, 4:33 AM

Tags for this Thread

Posting Permissions

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