Howto render Grid Cell with data from two fields?
In GXT2 I used to have a ListStore of a model containing the fields "unit" and "value". Then I created a Grid using the ListStore and a ColumnModel. The ColumnModel had a ColumnConfig for the "value" field. This ColumnConfig got a Renderer for showing "unit" next to "value" in that column.
GXT 2 - Code
Code:
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig valueColumn = new ColumnConfig("value", "value", 100);
valueColumn.setAlignment(HorizontalAlignment.RIGHT);
valueColumn.setRenderer(unitRenderer);
configs.add(valueColumn);
ColumnModel cm = new ColumnModel(configs);
Grid<MyModel> grid = new Grid<MyModel>(ingrStore, cm);
With the unitRenderer being:
Code:
public static final GridCellRenderer<MyModel> unitRenderer = new GridCellRenderer<MyModel>() {
@Override
public Object render(MyModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<MyModel> store, Grid<MyModel> grid) {
Double value = model.get(property);
if (value == null) {
return "";
}
String unit = model.getUnit();
return value.toString() + " " + unit;
}
};
Question: How to accomplish this in GXT3?
I know about setCell() and the render-Method there. But Model, Store and Grid aren't accessible over there.
What I got so far (GXT 3):
Code:
ColumnConfig<MyModel, Double> valueColumn= new ColumnConfig<MyModel, Double>(props.value(), 100, "value");
valueColumn.setCell(new PropertyDisplayCell<Double>(new DoublePropertyEditor(numberFormat)) {
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, Double value, SafeHtmlBuilder sb) {
String unit = "unit";//FIXME: How to get unit out of model here?
sb.appendHtmlConstant("<span>" + value.toString() + " " + unit + "</span>"); }
});