Search in sources :

Example 1 with GridCellRenderer

use of com.extjs.gxt.ui.client.widget.grid.GridCellRenderer in project activityinfo by bedatadriven.

the class ColumnModelBuilder method addIndicatorColumn.

public ColumnConfig addIndicatorColumn(IndicatorDTO indicator, String header) {
    NumberField indicatorField = new NumberField();
    indicatorField.getPropertyEditor().setFormat(IndicatorNumberFormat.INSTANCE);
    ColumnConfig indicatorColumn = new ColumnConfig(indicator.getPropertyName(), SafeHtmlUtils.fromString(header).asString(), 50);
    indicatorColumn.setNumberFormat(IndicatorNumberFormat.INSTANCE);
    indicatorColumn.setEditor(new CellEditor(indicatorField));
    indicatorColumn.setAlignment(Style.HorizontalAlignment.RIGHT);
    // (it looks better if we don't)
    if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_SUM) {
        indicatorColumn.setRenderer(new GridCellRenderer() {

            @Override
            public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore listStore, Grid grid) {
                Double value = model.get(property);
                if (value != null && value != 0) {
                    return IndicatorNumberFormat.INSTANCE.format(value);
                } else {
                    return "";
                }
            }
        });
    }
    return indicatorColumn;
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) CellEditor(com.extjs.gxt.ui.client.widget.grid.CellEditor) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) ListStore(com.extjs.gxt.ui.client.store.ListStore) GridCellRenderer(com.extjs.gxt.ui.client.widget.grid.GridCellRenderer) TreeGridCellRenderer(com.extjs.gxt.ui.client.widget.treegrid.TreeGridCellRenderer)

Aggregations

ModelData (com.extjs.gxt.ui.client.data.ModelData)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 NumberField (com.extjs.gxt.ui.client.widget.form.NumberField)1 CellEditor (com.extjs.gxt.ui.client.widget.grid.CellEditor)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)1 Grid (com.extjs.gxt.ui.client.widget.grid.Grid)1 GridCellRenderer (com.extjs.gxt.ui.client.widget.grid.GridCellRenderer)1 TreeGridCellRenderer (com.extjs.gxt.ui.client.widget.treegrid.TreeGridCellRenderer)1