-
5 Jul 2010 2:16 AM #1
Loading tree data from local "nested store"
Loading tree data from local "nested store"
I have a problem which prevents me from implementing a true JSON ajax support so I cannot use TreeLoader to lazy-load data. Namely I am using salesforce apex and they still do not have support for ajax requests returning just pure JSON (the workaround of having a separate vf page for every kind of request is a pain). My solution with grids and flat JSONStore was using Google's JSON object and then loading data "offline" inside javascript using store.loadData(). This however does not work with trees as they insist on using TreeLoaders.
So my question is, if I do not need lazy-loading and I have a client-side JSON object with nested children formated exactly like the samples how can I load them into TreePanel or TreeGrid without relying on ajax? How can I build a tree node structure client-side and force tree to use it instead of calling server? I dont see any support for this approach.
-
5 Jul 2010 3:01 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
A TreeLoader can load all nodes, including children, as long as your data is returned with the correct syntax, e.g.
Code:[{ text: 'Node 1', children: [{ text: 'Node 1a', children: [{ text:' Node 1aA', leaf: true },{ text:' Node 1aB', leaf: true }] },{ text: 'Node 1b', leaf: true }] },{ text: 'Node 2', leaf: true }]
-
5 Jul 2010 4:23 AM #3
Ok, but how?
Lets say I have your JSON in an actual JSON object:
How do I show this inside treepanel/treegrid? As I said, this data is already on a page, no additional http requests, must use myData object.Code:var myData = [{ text: 'Node 1', children: [{ text: 'Node 1a', children: [{ text:' Node 1aA', leaf: true },{ text:' Node 1aB', leaf: true }] },{ text: 'Node 1b', leaf: true }] },{ text: 'Node 2', leaf: true }]; // magic code here
-
5 Jul 2010 4:29 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
Simply create your tree with:
Code:root: { children: [...] }
-
5 Jul 2010 5:14 AM #5
No joy,
I get "attributes' is null or not an object" (IE) or "Uncaught TypeError: Cannot set property 'uiProvider' of undefined" (Chrome) inside SetRootNode. Both indicating that SetRootNode expects node to have attributes. It seem as if root can only be TreeNode (or AsyncTreeNode or another descendant) or can be a configuration object instructing treenode on which type of node to create. I still do not see a way to use root to accomplish my task (though the documentation for treepanel is rather scarce on that matter and treegrid docs are not available yet).
-
5 Jul 2010 5:16 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
What exactly did you specify as the root?
-
5 Jul 2010 5:25 AM #7
root: myData
and
root: { children: myData }
though one of them showed data on IE (but it had an additional empty root node)
Slight offtopic: just to confirm, there is no way to have checkoxes in treegrid as you can in treepanel? The checked: true/false seems to have no effect on the treegrid.
-
5 Jul 2010 5:39 AM #8Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
And 'myData' contains...?
It seems that Ext.ux.tree.TreeGridNodeUI.renderElements forgets to render the checkbox. No idea why, but that would be easy to add.
-
5 Jul 2010 5:49 AM #9
myData is JSON object (as in the above message)
Another small question: is there a way to tell treegrid to expand columns to use the space? (as in viewConfig: {forceFit: true, autoFill: true } for regular grids)
-
5 Jul 2010 6:02 AM #10Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
Ext.ux.tree.TreeGrid.setRootNode assumes that the node is an Ext.tree.Node instance; again, no idea why!
Use:
Sorry, TreeGrid has not forceFit/autoFill support. You will have to update the column widths manually.Code:root: new Ext.tree.TreeNode({children: myData})
Similar Threads
-
GXT 2.1.0 - data binding does not work correctly for "nested" properties
By Golem in forum Ext GWT: Bugs (2.x)Replies: 0Last Post: 19 Jan 2010, 1:23 AM -
[CLOSED][3.0] SetValue shows "valueField" instead of "displayField". mode "local".
By galdaka in forum Ext 3.x: BugsReplies: 3Last Post: 28 Oct 2009, 6:38 AM -
[CLOSED] Tree Loading style ("my-tree-loading") not cleared after loading
By Donald in forum Ext GWT: Bugs (1.x)Replies: 7Last Post: 23 Jul 2008, 8:35 AM -
Is there a way to show progress "wait" screen while loading data into a grid?
By pocketmax in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 5 Mar 2008, 12:11 PM


Reply With Quote