PDA

View Full Version : GridCellRender not updating



babyblue
12 Aug 2009, 11:03 AM
I have a GridCellRender that returns a LayoutContainer with HBoxLayout, it works the first time the table is shown, but if I remove the table and add it back into a container, the cell appears blank. The other cell render seems to work fine.



public static ContentPanel createTableWithRenderer() {
GridCellRenderer<BaseModel> greyCellRenderer = new GridCellRenderer<BaseModel>(){
public Object render(final BaseModel model, String property,
ColumnData config,
final int rowIndex, final int colIndex,
ListStore<BaseModel> store, Grid<BaseModel> grid) {
if(config.style == null)
{
config.style = SPECIAL_CSS_STYLE;
}
else if(!config.style.contains(SPECIAL_CSS_STYLE))
{
config.style = SPECIAL_CSS_STYLE + config.style;
}

return model.get(property);
}
};

GridCellRenderer<BaseModel> multiColorCellRenderer = new GridCellRenderer<BaseModel>(){
public Object render(final BaseModel model, String property,
ColumnData config,
final int rowIndex, final int colIndex,
ListStore<BaseModel> store, Grid<BaseModel> grid) {
LayoutContainer container = new LayoutContainer();
container.setBorders(false);
container.setHeight(20); // must have this

HBoxLayout layout = new HBoxLayout();
layout.setHBoxLayoutAlign(HBoxLayoutAlign.STRETCH);
container.setLayout(layout);

for(int c = 0; c < COLORS.length; c++) {
HBoxLayoutData flex = new HBoxLayoutData(new Margins(0, 0, 0, 0));
flex.setFlex(Math.random()*100);
LayoutContainer cell = new LayoutContainer();
cell.addText("");
cell.setStyleAttribute("background-color", "#"+COLORS[c]);
container.add(cell, flex);
}
return container;
}
};

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig("name", "Unit", 100);
configs.add(column);

column = new ColumnConfig("01", "0100", 100);
column.setRenderer(greyCellRenderer);
configs.add(column);

column = new ColumnConfig("02", "0200", 100);
column.setRenderer(multiColorCellRenderer);
configs.add(column);

ArrayList<BaseModel> list = new ArrayList<BaseModel>();
BaseModel model = new BaseModel();
model.set("name", "test");
model.set("01", "v1");
model.set("02", "v2");
list.add(model);

ListStore<BaseModel> store = new ListStore<BaseModel>();
store.add(list);

ColumnModel cm = new ColumnModel(configs);

ContentPanel cp = new ContentPanel();
cp.setBodyBorder(false);
cp.setHeading("Table");
cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.setSize(600, 400);

Grid<BaseModel> grid = new Grid<BaseModel>(store, cm);
grid.setStyleAttribute("borderTop", "none");
grid.setAutoExpandColumn("name");
grid.setBorders(true);
cp.add(grid);

return cp;
}


I add this table to the main LayoutContainer, and use a toggle button to add and remove it, then do a layout() call on the main LayoutContainer.



toggle.addSelectionListener(new SelectionListener<ButtonEvent>(){
@Override
public void componentSelected(ButtonEvent ce){
p.removeAll();
if(current == a) {
p.add(b);
current = b;
}else {
p.add(a);
current = a;
}
p.layout();
}
});


Any idea? How can I force it to rerender?

christian.schmuelling
13 Aug 2009, 12:46 AM
I can't help you. But you're not alone. I've the same problem.

Did you try it with IE or with Firefox? I have this problem just with IE. In Firefox I can see my grid content.

I'm using a similar way to switch the components. Maybee that's the problem.

With best regards
Christian

babyblue
13 Aug 2009, 9:38 AM
I just tried returning a single button, that has the same effect, so it looks like anything other than string? And yes, IE only bug, tested IE6, IE6, chrome and firefox 2.