SmartGWT TreeGrid, adding and editing
- by Banang
I'm trying to programmatically add a new TreeNode to a TreeGrid, and then turn on editing for the newly added node.
This is my data source:
DataSource ds = new DataSource();
DataSourceTextField idField = new DataSourceTextField("key", "Id");
DataSourceTextField nameField = new DataSourceTextField("name", "Name");
DataSourceTextField keyField = new DataSourceTextField("id", "Key");
keyField.setPrimaryKey(true);
ds.setFields(idField, keyField, nameField);
ds.setClientOnly(true);
My fields:
TreeGridField name = new TreeGridField("name", "Name");
TreeGridField id = new TreeGridField("id", "Id");
TreeGridField key = new TreeGridField("key", "Key");
key.setHidden(true);
id.setHidden(true);
And my code for adding a new record:
TreeNode parent = (TreeNode) treeGrid.getSelectedRecord();
if (parent == null)
parent = treeGrid.getData().getRoot();
Tree data = treeGrid.getData();
node = data.add(node, parent);
Now, how on earth do I switch on editing for the added node? I've tried startEditing(), but that defaults to the first node, and I don't see any way of obtaining the row number for the newly added node, which would allow me to use startEditing(rowNum, colNum, suppressFocus). Using startEditNew() is not an option for many reasons, mainly because that method adds the new node to the bottom of the tree, which doesn't work at all with my app.
How do I do this? Grateful for any help you guys can give me.