PDA

View Full Version : how do i can set styles for several columns via TreeGridCellRenderer



treblereel
18 Apr 2011, 8:26 AM
Hi all, example below works only for the first column, but i need something like this for the several columns.



name.setRenderer(new TreeGridCellRenderer<ModelData>() {

@SuppressWarnings("unchecked")
public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store,
Grid<ModelData> grid) {

if(blabla== true){
config.css = "x-treegrid-column-red";
}else{
config.css = "x-treegrid-column-green";
}


assert grid instanceof TreeGrid : "TreeGridCellRenderer can only be used in a TreeGrid";

@SuppressWarnings("rawtypes")
TreeGrid tree = (TreeGrid) grid;
@SuppressWarnings("rawtypes")
TreeStore ts = tree.getTreeStore();
int level = ts.getDepth(model);
String id = getId(tree, model, property, rowIndex, colIndex);
String text = getText(tree, model, property, rowIndex, colIndex);
AbstractImagePrototype icon = calculateIconStyle(tree, model, property, rowIndex, colIndex);
Joint j = calcualteJoint(tree, model, property, rowIndex, colIndex);
return tree.getTreeView().getTemplate(model, id, text, icon, false, j, level - 1);
}

});

micgala
18 Apr 2011, 11:48 PM
A TreeGrid can only have one TreeGridCellRenderer set... and it is for the first column.

For the other columns, you must set a normal GridCellRenderer, and then you can style things on it.

Regards,
Michel.

sven
18 Apr 2011, 11:57 PM
A TreeGrid can only have one TreeGridCellRenderer set... and it is for the first column.


You can have it on any column, but you can only have one column with a TreeGridCellRenderer

micgala
19 Apr 2011, 12:03 AM
You can have it on any column, but you can only have one column with a TreeGridCellRenderer
You are right... normally we use it for the first column :)
But it is not a rule.