On page 78 of the Book we see how to set the style for a cell in a table. In the example on page 84 for generated columns, we see how to set the style for the content of the cell (in this case, a Label). How does one set the style for the cell that contains the label when using a column generator (in this case, the td around the div that holds the label) ? I want to set the whole cell to have a different color if my generated content is a negative number, as opposed to changing the color of the number inside the cell.
Hi,
Would this help?
Sampler: Table Cell Styling
(click the “Show Java source” button under the sample title).
Perfect, it worked for me, and it is logical that the CellStyleGenerator does the work. But then there is a bug in the documentation. Page 84 of the book explicitly says
The passage looks like there was some reason for writing it. The behaviour may have changed since then, have to check and fix. Thanks!
The interactions between highlight mode in reindeer and the cell styling are not obvious due to the use of background and shadow (different browsers give different results – IE7 gives priority to background over background-color, whereas Chrome and Firefox do the opposite).
In order to fix this and get consistent behaviour across all three browsers (namely, showing the cell colour and getting rid of the shadow), I had to use
.v-table-cell-content-success, .v-selected .v-table-cell-content-success
{background: none; background-color: lime; color: black; font-style:normal; text-shadow: none; }
I could have done the opposite by copying things from reindeer to override my cell style. It would be better if cell styling was called with information regarding the selected line, so that the cell styler could just return null and leave the highlight style alone.
Is this still valid?
I am trying to syle a row based on the contents of a generated column in 7.6.4, but when I try to retrieve the value in the styleGenerator I get a NullPointerException.
Here is my code; I put this in the constructor of the Table.
Generating the column:
addGeneratedColumn("lastFaxJob", new Table.ColumnGenerator()
{
@Override
public Object generateCell(Table source, Object itemId, Object columnId)
{
return "testVal";
}
});
Setting the style:
[code]
setCellStyleGenerator(new Table.CellStyleGenerator()
{
@Override
public String getStyle(Table source, Object itemId, Object propertyId)
{
String status = "";
//get values from table
try
{
status = (String) source.getItem(itemId)
.getItemProperty("lastFaxJob")
.getValue();
LogManager.log.warn(status);
}
catch (NullPointerException npe)
{
LogManager.log.warn("One or more table values were null");
}
if (status.startsWith("testVal"))
{
return "faxSuccess";
}
else
{
return null;
}
}
});
[/code]Any help is greatly appreciated.