1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    3
    Vote Rating
    0
    ManoloComo is on a distinguished road

      0  

    Default Unanswered: Dynamic Grid in GXT 3.0

    Unanswered: Dynamic Grid in GXT 3.0


    I have to create a basic grid:

    DataProperties dp = GWT.create(DataProperties.class);


    List<ColumnConfig<Data, ?>> ccs = new LinkedList<ColumnConfig<Data, ?>>();
    ccs.add(new ColumnConfig<Data, String>(dp.name(), 200, "Name"));
    ccs.add(new ColumnConfig<Data, String>(dp.value(), 200, "Value"));
    ColumnModel<Data> cm = new ColumnModel<Test.Data>(ccs);


    ListStore<Data> s = new ListStore<Test.Data>(dp.key());
    s.add(new Data("name1", "value1"));
    s.add(new Data("name2", "value2"));
    s.add(new Data("name3", "value3"));
    s.add(new Data("name4", "value4"));


    Grid<Data> g = new Grid<Data>(s, cm);


    RootPanel.get().add(g);


    ////////////////////////////////////


    public interface DataProperties extends PropertyAccess {
    @Path("name")
    ModelKeyProvider key();
    ValueProvider<Data, String> name();
    ValueProvider<Data, String> value();
    }


    public class Data {
    private String name;
    private String value;


    public Data(String name, String value) {
    super();
    this.name = name;
    this.value = value;
    }
    public String getName() {
    return name;
    }
    public String getValue() {
    return value;
    }
    public void setName(String name) {
    this.name = name;
    }
    public void setValue(String value) {
    this.value = value;
    }
    }



    To do it I need of:
    1)a model(Data);
    2)an interface(DataProperties) that extends PropertyAccess,
    3)a ListStore (a container populated with the model,the ColumnConfig,the ColumnModel).
    It establishes the relationship between the table and the model.


    I would want to create that four elements(DataProperties,ListStore,ColumnConfig,ColumnModel) in a generic way so I can reuse them in another model.Is there a way to do it?

    Thanks

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Posts
    1,924
    Vote Rating
    55
    Answers
    73
    Colin Alworth is a jewel in the rough Colin Alworth is a jewel in the rough Colin Alworth is a jewel in the rough

      0  

    Default


    You do not need to use PropertyAccess to create grids, or anything in GXT. PropertyAccess is just a way to look at bean-like models, and provide access to ValueProviders, ModelKeyProviders, and LabelProviders within those beans. Often, if you have a dynamic data model, you can make your own such provider implementations that can generically read from your data model.

    Check out the ValueProvider section of this blog post http://www.sencha.com/blog/building-gxt-charts/ for a discussion on how to make a very dynamic data model and how to make ValueProviders that can read them. The example is made for Charts, but the same principle applies for Grids as well.

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    3
    Vote Rating
    0
    ManoloComo is on a distinguished road

      0  

    Default


    Thanks for you reply but I still have the problem.
    I don't know how create a my implementation of ValueProvider.


    My model:


    public class User extends GenericObj implements Serializable {
    private String userId;
    private String password;
    public String getUserId() {
    return userId;
    }
    public void setUserId(String userId) {
    this.userId = userId;
    }
    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    }


    My UserProperties:


    public interface UserProperties extends PropertyAccess<User> {
    @Path("name")
    ModelKeyProvider<User> key();
    ValueProvider<User, String> userId();
    ValueProvider<User, String> password();
    }


    MyView:


    private UserProperties userProperties = GWT.create(UserProperties.class);
    List<ColumnConfig<User, ?>> ccs = new LinkedList<ColumnConfig<User, ?>>();
    //my problem is here...
    ccs.add(new ColumnConfig<User, String>(userProperties.password(), 200, ""));
    ccs.add(new ColumnConfig<User, String>(userProperties.userId(), 200, ""));
    ....


    I'd want to create something as this:


    List<ColumnConfig<GenericObj, ?>> ccs = new LinkedList<ColumnConfig<GenericObj, ?>>();
    //for all fields of GenericObj
    ccs.add(new ColumnConfig<GenericObj, String>(*something that substitute the bold line*, 200, ""));


    Can I do it?
    Thanks in advice, Manolo

Tags for this Thread