Reputation: 14361
I have a client app that need to show a really big tree (It's a mega organizational budget) , which is available via JSON queries - each budget section has a code , and s.t topic 1122 is the son of topic 11 and the father of topic 112233.
The budget tree begins with high level topics , and what I want to do is this : when a user click on a topic node (for example , "11") , it will run a JSON query for all the sons of topic "11" , and then populate the tree with them.
So far I've managed to get the query to populate the tree with the high level nodes , but when you open a node , you get the same node list again.. :(
XJSONDataSource yedaDS = new XJSONDataSource();
yedaDS.setDataURL("http://api.yeda.us/data/gov/mof/budget/?o=jsonp&query=%7B%22code%22%20:%20%7B%20%22$regex%22%20:%20%22%5E0020%22%20%7D%7D");
DataSourceTextField code = new DataSourceTextField("code","Code");
code.setPrimaryKey(true);
yedaDS.setTitleField("title");
DataSourceIntegerField year = new DataSourceIntegerField("year", "Year");
DataSourceTextField netAllocation = new DataSourceTextField("title","Title");
yedaDS.setFields(code,year,netAllocation);
TreeGrid remoteJsonQuery = new TreeGrid();
remoteJsonQuery.setDataSource(yedaDS);
remoteJsonQuery.setAutoFetchData(true);
HStack stack = new HStack();
stack.addMember(remoteJsonQuery);
stack.draw();
Any ideas?
Upvotes: 1
Views: 1461
Reputation: 3609
In your case, you need to have 3 main things in your DS -
1) An Id field for each row eg - 112233
2) The parent Id for that row -- 1122 for this eg. You will have to add the foreign key relationship on this field. This is what you are missing
3) Root Value - 11, to tell the datasource which is/ are the root elements
As a code sample , look at the datasource code for this example, the important lines for you are -
DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId", "Employee ID");
employeeIdField.setPrimaryKey(true);
employeeIdField.setRequired(true);
DataSourceIntegerField reportsToField = new DataSourceIntegerField("ReportsTo", "Manager");
reportsToField.setRequired(true);
reportsToField.setForeignKey(id + ".EmployeeId");
reportsToField.setRootValue("11");
Upvotes: 1