Results 1 to 3 of 3

Thread: Design pattern for Grid without Bean property

  1. #1
    Sencha User
    Join Date
    Jun 2009
    Vote Rating

    Default Design pattern for Grid without Bean property

    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.

    GWT stuff twitter -!/gwtstuff

  2. #2
    Sencha User
    Join Date
    Feb 2009
    Vote Rating


    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.
    ColumnConfig<MyData, MyData> column = new ColumnConfig<MyData, MyData>(new IdentityValueProvider<MyData>());
    column.setCell(new AbstractCell<MyData>() {
      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.

    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
    Vote Rating

    Wink Design pattern for Grid without Bean property

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

    Stamp Image Bursting Application

Posting Permissions

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