You need to use a client only DataSource with the required .xml file.
datasource.xml Based on the sample:
<List>
<employee>
<EmployeeId>4</EmployeeId>
<Name>Charles Madigen</Name>
<Job>Chief Operating Officer</Job>
</employee>
<employee>
<EmployeeId>192</EmployeeId>
<Name>Ralph Brogan</Name>
<Job>Mgr Software Client Supp</Job>
</employee>
</List>
Place the datasource.xml in an accessible place in your web application.
http://<host>:<port>/testApp/data/datasource.xml
DataSource class:
public class EmployeeXmlDS extends DataSource {
public EmployeeXmlDS(String id) {
setRecordXPath("/List/employee"); // <== set proper XPath based on data
// other initialization and DataSourceField creation
setDataURL("data/datasource.xml"); // <== set Data URL based on above location
setClientOnly(true);
}
}
Create tree grid:
TreeGrid treeGrid = new TreeGrid();
// treeGrid.set* and other methods
TreeGridField nameField = new TreeGridField("Name", 150);
TreeGridField jobField = new TreeGridField("Job", 150);
treeGrid.setFields(nameField, jobField);
EmployeeXmlDS employeesDS = EmployeeXmlDS.getInstance();
treeGrid.setDataSource(employeesDS); // <== set the data source
NOTE: Only important sections of the code is listed above.
Its also possible to manually add nodes to the tree.
http://www.smartclient.com/smartgwt/showcase/#tree_checkbox
http://www.smartclient.com/smartgwt/showcase/#tree_interaction_drag_reparent
In SmartGWT showcase, when 'View Source' is selected, there could be multiple files related to the sample.
If there are multiple files, they will be listed as tabs, along with main source file.