I am trying to apply a Hilite to a ListGrid based on a (calculated) value. The code is shown below. The commented lines show ways I have tried to do this.
It seems like I cannot use the derived field in the criterion since it does not properly hilite when this field is used to specify the criterion.
I also tried to just repeat the calculation in the criterion but it looks like the 3rd argument creating the criterion cannot be the name of a field and must be a literal value.
Any suggestions on a way of applying the Hilite as attempted in the code below?
Thanks in advance!
I am using SmarGWT Power Edition 2.5 on FireFox.
It seems like I cannot use the derived field in the criterion since it does not properly hilite when this field is used to specify the criterion.
I also tried to just repeat the calculation in the criterion but it looks like the 3rd argument creating the criterion cannot be the name of a field and must be a literal value.
Any suggestions on a way of applying the Hilite as attempted in the code below?
Thanks in advance!
Code:
public class TestTable extends ListGrid
{
private static Hilite[] hilites = new Hilite[] {
new Hilite() {{
setFieldNames("ACTUAL", "EXPECTED", "MARGIN");
setCriteria(new Criterion("MARGIN", OperatorId.LESS_OR_EQUAL, 1000.0f));
// setCriteria(new Criterion("ACTUAL", OperatorId.LESS_OR_EQUAL, "EXPECTED"));
setTextColor("#3333FF");
setId("0");
}},
new Hilite() {{
setFieldNames("PG_LATENCY","EXPECTED","MARGIN");
setCriteria(new Criterion("MARGIN", OperatorId.GREATER_THAN, 1000.0f));
// setCriteria(new Criterion("ACTUAL", OperatorId.GREATER_THAN, "EXPECTED"));
setTextColor("#FF0000");
setId("1");
}}
};
public TestTable()
{
//Setup the information needed for interacting with the DataSource
DataSource productTimingDataSource = DataSource.get("TestDataSource");
this.setDataSource(TestDataSource);
this.setAutoFetchData(true);
//Set the Table to allow basic filtering in a small menu above the table.
this.setShowFilterEditor(true);
//Create ListGrid Fields for each of the fields you want from the DataSource
List<ListGridField> listGridFields = new ArrayList<ListGridField>();
for(String fieldNameFromDataSource : productTimingDataSource.getFieldNames())
{
listGridFields.add(new ListGridField(fieldNameFromDataSource));
}
//Create a derived field for the ListGrid. This field does not exist directly
//in the DataSource, but is calculated from the DataSource fields.
ListGridField calculatedField = new ListGridField("MARGIN", "Margin");
calculatedField.setCellFormatter(new CellFormatter()
{
@Override
public String format(Object value, ListGridRecord record, int rowNum, int colNum)
{
double actual = record.getAttributeAsDouble("ACTUAL");
double expected = record.getAttributeAsDouble("EXPECTED");
double margin = expected - actual;
return String.valueOf(margin);
}
});
listGridFields.add(calculatedField);
//Add both the datasource and derived fields to the ListGrid.
ListGridField[] listGridFieldsAsArray = (ListGridField[]) listGridFields.toArray(new ListGridField[listGridFields.size()]);
this.setFields(listGridFieldsAsArray);
this.setHilites(hilites);
}
}
Comment