1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    4
    Vote Rating
    0
    Pro1712 is on a distinguished road

      0  

    Default Data Binding

    Data Binding


    Hi!

    I'm new to GWT / GXT.

    How can I do generic data binding with a grid / tree / textfield, ...?

    I've got a database with more than 500 tables and thousands of queries.
    I can't create interafces and classes for every query!

    The approach in the samples with classes an interafces for every object is ok for a small number of objects but not for a huge numer of objects.
    So how can I handle this?

    Thanks for your help!

  2. #2
    Sencha User
    Join Date
    Oct 2008
    Posts
    16
    Vote Rating
    0
    Fedy2 is on a distinguished road

      0  

    Default


    Hi,
    I have the same problem. We're creating a generic system for visualizing tables therefore we can't create a data model for each table.
    With GXT 2.X you can use the ModelData interface to "create" those fields dynamically, but I can't find a solution for GXT 3.

    Someone has already faced with this problem?

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    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


    GXT 3 is if anything more flexible than 2.x - while it is encouraged to use bean-like objects, there is no reason you can't write a ModelData-like class with string-based properties.

    Stores, DataLoaders, and DataProxys are all generic enough to handle any type at all, and the requirements of the data widgets are merely to implement a ValueProvider instance to read and write values as needed.

    For a hypothetical example, you could pass Map<String, Double> as your data to and from the server. You'd then have a ListStore<Map<String, Double>>, and a Grid<Map<String, Double>>. Each column could have a hand made ValueProvider (this is just an interface, you can implement it however you'd like) that may look about like this:

    Code:
    public class MapValueProvider implements ValueProvider<Map<String, Double>, Double> {
      private final String property;
      public MapValueProvider(String property) {
        this.property = property;
      }
      public String getPath() {
        return property;
      }
      public Double getValue(Map<String, Double> object) {
        return object.get(property);
      }
      public void setValue(Map<String, Double> object, Double value) {
        object.put(property, value);
      }
    }
    You then could create ColumnConfig instances using these, something like
    Code:
    ColumnConfig<Map<String, Double>, Double> column =
          new ColumnConfig<Map<String, Double>, Double>(new MapValueProvider("prop");
    Several columns can be added with different properties they are reading from each row.

    Likely you'd be using your own Java class that exposes some kind of getter method to read from these dynamic properties, like ModelData did in 2.x.

  4. #4
    Sencha User
    Join Date
    Oct 2008
    Posts
    16
    Vote Rating
    0
    Fedy2 is on a distinguished road

      0  

    Default


    Thank you for your reply.

    Finally I've adopted a similar solution adding support for different types of data (String, Long, Boolean and so on) and creating a JSON data reader for runtime defined model data.

  5. #5
    Sencha Premium Member
    Join Date
    Jun 2012
    Posts
    1
    Vote Rating
    0
    alibresc is on a distinguished road

      0  

    Default


    Hi,

    I need a solution that combine defining specific data and a large data of any type String, date, float etc. (which can be created dynamically in my system with its type and value).


    How can I create a grid that accepts different types of data: String, date, float and map<String, Object>?

    Thanks for your help!

  6. #6
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    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


    What have you tried? Even providing a simple example would go a long ways, as your question isn't quite clear.

    If you want the Grid itself to contain any of these kinds of data, then you'll need to define a ListStore<Object> and a Grid<Object> with all of the issues that start from there - defining a ModelKeyProvider<Object> that works for String, Date, Float, Map<String, Object> for example.

    The next step is to build a ColumnConfig and ValueProvider that can read from any of these types of data - though I'm not clear on how a grid row that is displaying a single String would make use of multiple columns.

    If you want the Grid to contain some object defined in your code and have each _column_ display String, Date, Float, Map, then you'll define the ListStore and Grid to be generic on whatever it is you are holding the data in, and build a ValueProvider that can read from that object. Without seeing how you intend to store that data, I'd have to guess at what you might be thinking.

    Define the data model first, some Java object that makes sense to contain all of these pieces of data, and it should become clear how to build a ValueProvider that can read that exact data type out, even if it involves an extra cast or two.