Dec 20

To include a calculated field in a ListGrid you need to create a new ListGridField and specify the cellFormatter property to handle calculating the fields value.

// Following example shows a data source that return two fields
// firstName and lastName
// A CellFormatter is used to concatenate the first and last name
// in a single field in the ListGrid

DataSource peopleDS = new RestDataSource();
peopleDS.addField(new DataSourceTextField("firstName"));
peopleDS.addField(new DataSourceTextField("lastName"));

final ListGrid people = new ListGrid();

// Create a new "Name" field in ListGrid

ListGridField name = new ListGridField("name", "Name");

// Specify a CellFormatter to calculate the fields value

name.setCellFormatter(new CellFormatter()
   public String format(Object value, ListGridRecord record,
      int row, int column)
        // Get 'firstName' and 'lastName' values 
        // from record being displayed

        String firstName = record.getAttributeAsString("firstName");
        String lastName = record.getAttributeAsString("lastName");

        // return concatenated name

        return firstName + " " + lastName;

// Add calculated field to the ListGrid


written by objects \\ tags: , , ,

Array ( ) One Response to “Can I have a calculated field in a SmartGWT ListGrid?”

  1. pawloch Says:

    I might be wrong, but that is sooo slow…. it makes my not-so-big (2 rows, 30 columns) table load 3 seconds I used it to put two fields into one column (checkbox + data)

    Ovverriding protected Canvas createRecordComponent(,,) from ListGrid gives much better results as I tried it from Smartgwt Widget example. Then table takes only miliseconds to load

Leave a Reply

You must be logged in to post a comment.