-
30 Mar 2010 11:26 AM #1
Rendering checkbox in treegrid
Rendering checkbox in treegrid
Two questions: 1) I'm trying to figure out how to use a renderer for a checkbox in a treegrid. I want to hide the checkbox at the parent levels. I'm trying this but it doesn't work - the check box renders in one of the children but not the others.
Is there a better way to do this?
CheckColumnConfig checkColumn = new CheckColumnConfig(template.isAutoLogOn.toString(), "AUTOLOG?", 60);
final CheckBox cb = new CheckBox();
checkColumn.setRenderer(new GridCellRenderer<ModelData>(){
@Override public Object render(ModelData model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<ModelData> store, Grid<ModelData> grid) {
if (model.get("type").equals("resource")) {
cb.setVisible(false);
return cb;
}
else {
cb.setVisible(true);
return cb;
}
}
});
CellEditor checkBoxEditor = new CellEditor(cb);
checkColumn.setEditor(checkBoxEditor);
columns.add(checkColumn);
Question 2) Is there a good example of how to render fields in the parent row based on data in the child rows? If the user updates a child row, I want to update the parent without having to round trip data to the server.
Thanks!
-
5 Apr 2010 7:13 AM #2
i thing i did something similar to your question 1.
first i make a class to overrhide CheckColumnConfig.onRender
and then i use id in my column configCode:public class myCheckColumnConfig extends CheckColumnConfig { public myCheckColumnConfig (String id, String name, int width) { super(id, name, width); } protected String onRender(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store) { if (model instanceof myModel) { config.css = "x-grid3-check-col-td"; return "<div class='x-grid3-check-col" + " x-grid3-check-col" + getCheckState(model, property, rowIndex, colIndex) + " x-grid3-cc-" + getId() + "'> </div>"; } return ""; } }
Code:ColumnConfig cc= new myCheckColumnConfig("toto", "Toto", 75); CellEditor checkBoxEditor = new CellEditor(new CheckBox()); cc.setEditor(checkBoxEditor); cc.add(cc);


Reply With Quote