dhphuoc
3 Jan 2011, 8:28 AM
Hi,
I am trying to implement the checkbox functionality on a TreeGrid, so that it'll behave somewhat similarly as a checkable TreePanel. I am aware that GXT v3.0 will have the tri-state checkbox TreeGrid as a few feature, but I still need to implement this feature for now unfortunately. I try to override the TreeGridCellRenderer and pass <true> to the getTemplate() call as shown below. The checkboxes render correctly, however, they don't seem to accept the mouse events. I check and un-check the boxes but they are not visually changing their state accordingly. Does anyone know what I am missing? Also, if you know some high-level steps to implement this feature, your sharing/feedback is appreciated. Thanks.
ColumnConfig name = new ColumnConfig("name", "Name", 100);
name.setRenderer(new TreeGridCheckboxCellRenderer<ModelData>());
public class TreeGridCheckboxCellRenderer<M extends ModelData> extends TreeGridCellRenderer<M> {
@SuppressWarnings({"unchecked", "rawtypes"})
public Object render(M model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<M> store,
Grid<M> grid) {
config.css = "x-treegrid-column";
assert grid instanceof TreeGrid : "TreeGridCellRenderer can only be used in a TreeGrid";
TreeGrid tree = (TreeGrid) grid;
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, true, j, level - 1);
}
}
I am trying to implement the checkbox functionality on a TreeGrid, so that it'll behave somewhat similarly as a checkable TreePanel. I am aware that GXT v3.0 will have the tri-state checkbox TreeGrid as a few feature, but I still need to implement this feature for now unfortunately. I try to override the TreeGridCellRenderer and pass <true> to the getTemplate() call as shown below. The checkboxes render correctly, however, they don't seem to accept the mouse events. I check and un-check the boxes but they are not visually changing their state accordingly. Does anyone know what I am missing? Also, if you know some high-level steps to implement this feature, your sharing/feedback is appreciated. Thanks.
ColumnConfig name = new ColumnConfig("name", "Name", 100);
name.setRenderer(new TreeGridCheckboxCellRenderer<ModelData>());
public class TreeGridCheckboxCellRenderer<M extends ModelData> extends TreeGridCellRenderer<M> {
@SuppressWarnings({"unchecked", "rawtypes"})
public Object render(M model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<M> store,
Grid<M> grid) {
config.css = "x-treegrid-column";
assert grid instanceof TreeGrid : "TreeGridCellRenderer can only be used in a TreeGrid";
TreeGrid tree = (TreeGrid) grid;
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, true, j, level - 1);
}
}