Results 1 to 3 of 3

Thread: GXT3 dynamic number of columns

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    LA
    Posts
    42
    Answers
    1

    Default GXT3 dynamic number of columns

    Hi,

    i'm trying to create a table with a variable number of columns
    i have an object with 2 properties:
    - the name
    - a list of values

    i want the table to display the name as column 1 and for column 2 3 4 ... to display the data from the property represented as a list.

    now searching all over the internet i found 2 possible solutions @Path annotation or building a custom value provider

    but:
    1) i could not figure out how to make a path annotation like
    @Path("resultList") and add an index to it (i would not prefer this idea too much as it assumes i'll hard code a lot and defies the purpose of a true dynamic number of columns)

    2) i could not figure out how to write a custom value provider that will take an index as an argument and return the data fro that index


    Code:
    //this works
    ColumnConfig<Compare, String>  nameColumn  = new ColumnConfig<Compare, String>(resultsProps.name(),      80,  "Name");
    someColumnConfigList.add(nameColumn);
    //this does not
    for (int i, i < size of resultList, i++) {
         ColumnConfig<Compare, String>  someColumn         = new ColumnConfig<Compare, String>(new CUstomValueProvide(1),           80,  "C"+i.toString());
         someColumnConfigList.add(someColumn);
    }
    Code:
    public class Compare implements Serializable {
    
    
        private static int ID = 0;
        private String name;
        private List<String> resultList;
        
        private int id;
    
    
        public Compare() {
            this.id = ID++;
        }
        
        public Compare(String name, List<String> resultList) {
            this();
            this.setName(name);
            this.setResultList(resultList);
        }

    any ideas ? how to build a custom value provider able to access different indexes of the "resultList"

  2. #2
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,165
    Answers
    12

    Default

    For dynamic columns I might suggest using a anonymous value provider instead of a property. Both do the same job. If you use the second example below would give you some more options in dynamically configuring your columns. If you're not sure quite yet with this, let me know and I can dive deeper.

    - Example uses a property
    Code:
    ColumnConfig<StateTestModel, String> nameCol = new ColumnConfig<StateTestModel, String>(props.name(), 50, "Name");
    - Example uses an anonymous ValueProvider which is the same as the first example.
    Code:
    ColumnConfig<StateTestModel, String> nameCol2 = new ColumnConfig<StateTestModel, String>(new ValueProvider<StateTestModel, String>() {
      @Override
      public String getValue(StateTestModel object) {
        return object.getName();
      }
    
    
      @Override
      public void setValue(StateTestModel object, String value) {
        object.setName(value);
      }
    
    
      @Override
      public String getPath() {
        return null;
      }
    }, 50, "Name");
    Hope that helps,
    Brandon

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    88
    Answers
    2

    Default

    Write your value provider by creating a class and implementing ValueProvider<Compare,String>:

    (untested)
    Code:
    MyValueProvider implements ValueProvider<Compare,String>{
        private final int index;
    
    
        public MyValueProvider(int index){
            this.index = index;
        }
        
        @Override
        public String getValue(Compare object) {
            return object.getResultList().get(i);
        }
    
    
        @Override
        public void setValue(Compare object, String value) {
            // if you need this you have to put the value in the resultList at the position 'index'
        }
    
    
        @Override
        public String getPath() {
            return "dynamicValueProvider";
        }    
    
    
    }
    Now you can create your column and pass your value provider:

    Code:
    new MyValueProvider(5); // 5th entry in the list

Posting Permissions

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