In a Table, I want to set a cell’s style based on another cell’s contents.
So I have a cell style generator working. The problem is the “getStyle” method is passed only an itemId and a propertyId. I need access to another property on the same item.
→ How do I get to an Item instance from only the itemId?
So in this example, I want the FirstName cell to have color if that person is a boss (“IsBoss” property).
// style generator
// The returned style name will be concatenated to prefix "v-table-cell-content-".
table.setCellStyleGenerator(new Table.CellStyleGenerator() {
public String getStyle(Object itemId, Object propertyId) {
if (propertyId == null) {
// no propertyId, styling row
return null;
} else if ("FirstName".equals(propertyId)) {
// How do I get the item?
// I need a sibling property on the same item.
if ( item.getItemProperty( "IsBoss" ).getValue() ) == true ) {
return "is_boss";
} else {
return null;
}
} else {
// no style
return null;
}
}
});