1. #1
    Sencha User
    Join Date
    May 2010
    Posts
    16
    Vote Rating
    0
    marvic is on a distinguished road

      0  

    Default Unanswered: Create TreeGrid Problem

    Unanswered: Create TreeGrid Problem


    Hi.

    I want to create TreeGrid for this model:

    Code:
    public class Criteria implements Serializable {
    
    
        int id;
        String description;
        Rubric rubric;
    
    
        public Criteria() {
        }
        public Criteria(int id) {
            super();
            this.id = id;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getDescription() {
            return description;
        }
        public void setDescription(String description) {
            this.description = description;
        }
        public Rubric getRubric() {
            return rubric;
        }
        public void setRubric(Rubric rubric) {
            this.rubric = rubric;
        }
    }
    
    public interface CriteriaProp extends PropertyAccess<Criteria> {
    
    
        @Path("id")
             ModelKeyProvider<Criteria> id();
    
    
        @Path("description")
        LabelProvider<Criteria>descriptionLabel();
    
    
        ValueProvider<Criteria, String> description();
        ValueProvider<Criteria, Rubric> rubric();
        
        @Path("rubric.description") 
        ValueProvider<Criteria, String> rubricDescription();
    }
    
    
    public class Rubric  implements Serializable {
    
    
        int id;
        String description;
    
    
        public Rubric () {
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getDescription() {
            return description;
        }
        public void setDescription(String description) {
            this.description = description;
        }
    
    
    }
    Rubric.description - must be root element and Criteria.description - child (as grouping by Rubric.description).
    I'm trying to do so:
    Code:
                   RpcProxy<Criteria, List<Criteria>> proxyTree = new RpcProxy<Criteria, List<Criteria>>() {
    
    
                @Override
                public void load(Criteria loadConfig,
                        AsyncCallback<List<Criteria>> callback) {
                    service.getCriteriaTree(loadConfig, callback);
                }
            };
    
    
            final TreeLoader<Criteria> loaderTree = new TreeLoader<Criteria>(
                    proxyTree) {
                @Override
                public boolean hasChildren(Criteria parent) {
                    return parent.getRubric() instanceof Rubric;
                }
            };
    
    
                   CriteriaProp props = GWT.create(CriteriaProp.class);        
                   TreeStore<Criteria> store = new TreeStore<Criteria>(props.id());
            loaderTree.addLoadHandler(new ChildTreeStoreBinding<Criteria>(store));
            ColumnConfig<Criteria, String> rubcol = new ColumnConfig<Criteria, String>(
                    props.rubricDescription(), 150, "Rubric");
            ColumnConfig<Criteria, String> critcol = new ColumnConfig<Criteria, String>(
                    props.description(), 500, "Criteria");
    
    
            List<ColumnConfig<Criteria, ?>> l = new ArrayList<ColumnConfig<Criteria, ?>>();
            l.add(rubcol);
            l.add(critcol);
            ColumnModel<Criteria> cm = new ColumnModel<Criteria>(l);
    
    
            TreeGrid<Criteria> treeGrid = new TreeGrid<Criteria>(store, cm, rubcol);
                    loaderTree.load();
    ////////////////////////////////////////////
            
                  //  Impl service:
            @Override
        public List<Criteria> getCriteriaTree(Criteria loadConfig) {
            List<Criteria> sources = null;
            sources = infoManager.getCriteria();
            return sources;
        }
    but it's wrong code - display only critcol as root.
    Help please write the correct code.

    Thanks.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Answers
    109
    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


    but it's wrong code - display only critcol as root/
    I'm sorry, can you clarify that at all? I'm not sure what you mean by "critcol"?

    The TreeStore may have multiple root elements - if you only want one, be sure to only return one element when asked for an item with a null parent. That item (or items) will be added as the root of the tree, and will be used for the next request when it is made.

    As far as I can tell, your RPC service is responsible for actually putting together the items - you reference it here:
    Code:
            RpcProxy<Criteria, List<Criteria>> proxyTree = new RpcProxy<Criteria, List<Criteria>>() {
    
    
                @Override
                public void load(Criteria loadConfig,
                        AsyncCallback<List<Criteria>> callback) {
                    service.getCriteriaTree(loadConfig, callback);
                }
            };
    But without knowing what getCriteriaTree does, it is hard to say why you are not seeing the items you want.

  3. #3
    Sencha User
    Join Date
    May 2010
    Posts
    16
    Vote Rating
    0
    marvic is on a distinguished road

      0  

    Default


    Consider a simple example.
    All data is stored in the database.

    Code:
    public class Country {
      int id;
      String name;
    ....
    }
    
    public class State {
      int id;
      String name;
      int country_id;
    ....
    }
    
    public class City {
      int id;
      String name;
      int state_id;
    ....
    }
    
    public class People {
      int id;
      String name;
      String gender;
      int age;
      int city_id;
    .........
    }
    How can I get such a TreeGrid ?

    Name Gander Age
    -------------------------------------------------
    -- Country1
    -- State1
    -- City1
    people1 M 25
    people2 F 20
    people3 M 30
    ....
    How to configure RpcProxy, TreeLoader and TreeStore? or how manually fill TreeStore ?

Thread Participants: 1

Tags for this Thread