1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    15
    Vote Rating
    0
    maticpetek is on a distinguished road

      0  

    Default Design pattern for Grid without Bean property

    Design pattern for Grid without Bean property


    Hello,
    I have a grid with different columns which values map into POJO object via ValueProperties interface. Now I would like to add one column which value is really calculate by application state + some bean states. How can I create ValueProperties method to get values if I don't have this calculate values in my bean? This was very easy in GXT 2.x :

    GridCellRenderer<BaseModelData> buttonRenderer = new GridCellRenderer<BaseModelData>() {
    public Object render(final BaseModelData model, String property, ColumnData config, final int rowIndex, final int colIndex, ListStore<BaseModelData> store, Grid<BaseModelData> grid) {
    ........
    }
    }

    Thank you for advice.

    Regards,
    Matic
    ------------------
    GWT stuff twitter - http://twitter.com/#!/gwtstuff

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


    There are several ways to accomplish the same thing, depending on exactly what it is you want to customize.

    The first, most exact translation of the code you've posted, would be to build a GWT Cell instance and attach it to your ColumnConfig. These uses SafeHtml to ensure that all content will be outputted correctly, and can accept events to make lightweight widget-like elements to draw cheaply.

    This sample assumes that you need the entire model to read from multiple properties of your bean to render content, and so uses the IdentityValueProvider, which makes sure that the model itself is passed to be drawn.
    Code:
    ColumnConfig<MyData, MyData> column = new ColumnConfig<MyData, MyData>(new IdentityValueProvider<MyData>());
    column.setCell(new AbstractCell<MyData>() {
      @Override
      public  void render(Context context, MyData value, SafeHtmlBuilder sb) {
        //append content to sb about the value object
      }
    });
    Alternatively, you could build a specific ValueProvider to turn the model's data into something that is ready to be drawn as-is. ValueProvider<M, V> is an interface that is used by data widget code to read and write values of type V on a model of type M in a generic way. PropertyAccess is frequently used to automatically generate ValueProvider instances, but you can just as easily implement your own.

    Code:
    class CustomValueProvider implements ValueProvider<MyData, String> {
      public String getValue(MyData data) {
        return data.getA() + data.getB();
      }
      public void setValue(MyData object, String value) {
        //do nothing, this is a read-only column, or build your own logic here
      }
      public String getPath() {
        return "";// this may be needed if you allow remote sorting/filtering on this column
                  // if so, this string is what will be passed to the server to represent this column.
      }
    }

  3. #3
    Ext JS Premium Member jadrake75's Avatar
    Join Date
    Sep 2008
    Posts
    108
    Vote Rating
    4
    jadrake75 is on a distinguished road

      0  

    Wink Design pattern for Grid without Bean property

    Design pattern for Grid without Bean property


    Great information and confirms my thoughts. This just saved me at least an hour of experimentation!

    -Jason
    Stamp Image Bursting Application
    see http://code.google.com/p/stamp-imagebursting/

Thread Participants: 2