I'm having trouble displaying nodes in the TreeGrid depending on the logical 'type' of the node (as returned by the rest datasource). I tried a few approaches (using latest nightly, gwt 2.1.1):
1. Setting the isFolder for the TreeGrid's dataArrived event:
This works for the initial display, but if I modify the node to another type, the tree grid doesn't change the type of the node, at least visually, as the event doesn't fire for updates.
2. Using FieldValueExtractor to calculate the value of the isFolder flag. This causes issues if I specify the isFolder field as DataSourceBooleanField (isBoolean validator fails), before it even hits the extractor, I assume because the property is not available in the recordset returned from the serverside.
This also had unexpected side effects, firefox would just hang there if I returned a boolean true/false from the DataSourceTextField field value extractor, and would work fine in chrome. Returning a string "true"/"false" in this case ended up making all nodes look like folders.
3. The closest I got to the expected functionality, was using DataSourceTextField, and returning "1" for folders and null for leaves. This changes the icon to a folder when type is changed to a CONTAINER, but does not change it back to a leaf icon when the node type is changed to a different type (and it has no children). I
and hooking the dataArrived event to introduce a dataChanged event on the treeGrid.getTree();
This looks like a terrible hack to me. What would be the smartgwt way to achieve this functionality?
regards,
Andrius J.
1. Setting the isFolder for the TreeGrid's dataArrived event:
Code:
record.setAttribute("CONTAINER".equals(record.getAttribute("type"))
2. Using FieldValueExtractor to calculate the value of the isFolder flag. This causes issues if I specify the isFolder field as DataSourceBooleanField (isBoolean validator fails), before it even hits the extractor, I assume because the property is not available in the recordset returned from the serverside.
This also had unexpected side effects, firefox would just hang there if I returned a boolean true/false from the DataSourceTextField field value extractor, and would work fine in chrome. Returning a string "true"/"false" in this case ended up making all nodes look like folders.
Code:
DataSourceField isFolder = new DataSourceTextField("isFolder", "Is container"); isFolder.setFieldValueExtractor(new FieldValueExtractor() { @Override public Object execute(Object record, Object value, DataSourceField field, String fieldName) { return ("CONTAINER".equals((new Record((JavaScriptObject) record)).getAttribute("type"))); } }); }
Code:
DataSourceField isFolder = new DataSourceTextField("isFolder", "Is container"); isFolder.setFieldValueExtractor(new FieldValueExtractor() { @Override public Object execute(Object record, Object value, DataSourceField field, String fieldName) { return ("CONTAINER".equals((new Record((JavaScriptObject) record)).getAttribute("type")))?"1":null; } });
Code:
treeGrid.addDataArrivedHandler(new DataArrivedHandler() { @Override public void onDataArrived(DataArrivedEvent event) { treeGrid.getTree().addDataChangedHandler(new DataChangedHandler() { @Override public void onDataChanged(DataChangedEvent event) { for (TreeNode node : treeGrid.getTree().getAllNodes()) { node.setAttribute("isFolder", "CONTAINER".equals(node.getAttribute("type"))); } } }); } });
regards,
Andrius J.
Comment