PDA

View Full Version : Colourize a Grid Row



Windcape
2 Feb 2010, 7:32 AM
Hi

I'm trying to colourize a row in my Grid. I'm doing this by applying a GridCellRenderer to the ColumnConfig, as I couldn't find any other way to do it.

However, the code have absolutly zero effect on the layout, so I'm wondering what's wrong here:



ColumnConfig sender = new ColumnConfig("sender", "Sender", 200);
sender.setRenderer(new GridCellRenderer<MailItem>() {
@Override
public Object render(MailItem model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<MailItem> store, Grid<MailItem> grid) {

grid.getView().getRow(rowIndex).getStyle()
.setProperty("backgroundColor", "red");

return model.get(property);
}
});

ColumnConfig email = new ColumnConfig("email", "Email", 100);
ColumnConfig subject = new ColumnConfig("subject", "Subject", 100);

ColumnModel cm = new ColumnModel(Arrays.asList(sender, email, subject));

store = new ListStore<MailItem>();

grid = new Grid<MailItem>(store, cm);
grid.getView().setForceFit(true);


Thanks.

systao
3 Feb 2010, 2:35 AM
hi,

I do this in my grids and it works; I paint even rows with one color different from the default one (grey).




gridView.setViewConfig(new GridViewConfig() {
@Override
public String getRowStyle(ModelData model, int rowIndex,
ListStore ds) {
if (rowIndex % 2 == 1)
return"odd_row"; //css
return"even_row"; //css
}
});



In css:




.odd_row

{ }
.even_row { background-color: #E4EEFC !important; }


[/CODE]