Hi
I have tried changing the column color in a table but the enitre row gets highlighted rather than cell (column balance). This is my code. I have a table which has 2 columns.,
and I want to change the column balance as stated.
@Override
protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) {
if (colId.equals("creditAmount")) {
BigDecimal amount = (BigDecimal) property.getValue();
return Utility.getPoundValue(amount);
}
else if (colId.equals("balance")) {
BigDecimal amount = (BigDecimal) property.getValue();
StringBuilder sqlBuilder = new StringBuilder();
if (amount.signum() < 0 )
return sqlBuilder.append(Utility.getPoundValue(amount);
else {
return sqlBuilder.append(Utility.getPoundValue(amount);
}
}
return super.formatPropertyValue(rowId, colId, property);
table.setCellStyleGenerator(new Table.CellStyleGenerator() {
@Override
public String getStyle(Table source, Object itemId, Object propertyId) {
Item item = table.getItem(itemId);
BigDecimal cellvalue = (BigDecimal) item.getItemProperty("balance").getValue();
if( cellvalue.toString().contains("-") ) {
return "green";
}
if( cellvalue.toString().contains("0.00") ) {
return "nothing";
}
else {
return "red";
}
}
});
The CSS I added was
.v-table-cell-content-nothing {
background-color: #00ff00;
}
.v-table-cell-content-green {
background-color: green;
}
.v-table-cell-content-red {
background-color: red;
}