EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: amir-t on July 14, 2013, 10:10:48 AM



Title: Tree grid - loading expanded node data with loader property
Post by: amir-t on July 14, 2013, 10:10:48 AM
Hi,
im tyring to implement a dynamic load, without using any url, but to make a custom loader which gets the data from web service. when i load the root level data, the loading is as expected,
but when expending one of the root parents, then the children data is overring the existed root level and not appended to the expanded parent (as its children data), but just replacing the all treeGrid data.

It's important to mention' that i've checked that the children data of the expanded node are as expected, and that all the chidrens holds the correct 'parentId' property,
which points to the expanded node that was pressed.

Code:
$('#treeDiv').treegrid({
loader: function(param, success, error) {
             if (!param.id) {

                data = getData();   // retrieve the top level data.
                success(data);
             }
             else {
                data = getData(param.id); // retrieve the children data of the current expanded node.
                success(data);                // here, the data will be replaced and won't be appended to the expanded node.
             }
        }
});

Example of the data:

root level:
Code:
[{id: 1,
name: 'parent 1',
parentId: 0}
]

children data of the expanded parent:
Code:
[{id: 11,
name: 'child 1',
parentId: 1},
{id: 12,
name: 'child 2',
parentId: 1},
{id: 13,
name: 'child 23',
parentId: 1}
]


Title: Re: Tree grid - loading expanded node data with loader property
Post by: stworthy on July 14, 2013, 07:48:50 PM
If you would like to expand a node to retrieve its children nodes, the node's state should be set to 'closed'. Please add 'state' property to the root node.
Code:
[{id: 1,
name: 'parent 1',
state: 'closed',
parentId: 0}
]


Title: Re: Tree grid - loading expanded node data with loader property
Post by: amir-t on July 15, 2013, 01:04:08 AM
Hi,

i tried your advice, but still doesn't work  :(

when i set the state property for some parent node as follows:
Code:
[{id: 1,
name: 'parent 1',
state: 'closed',
parentId: 0}
]

Still on the loader callback, after expanding the parent, this following code line still replaces all the tree's data instead of appending it to the expanded parent:

success(data);   

please notice the comments in this code block (the loader function scope):
Code:
$('#treeDiv').treegrid({
loader: function(param, success, error) {
             if (!param.id) {

                data = getData();   // retrieve the top level data.
                success(data);
             }
             else {
                data = getData(param.id); // retrieve the children data of the current expanded node.

                // this line still overrides the entire tree's data instead of appending the current data to the expanded parent
               success(data);   
             }
        }
});


Title: Re: Tree grid - loading expanded node data with loader property
Post by: stworthy on July 15, 2013, 01:22:45 AM
Please refer to this example http://jsfiddle.net/dvAcu/.


Title: Re: Tree grid - loading expanded node data with loader property
Post by: amir-t on July 15, 2013, 03:55:05 AM
Works fine now.
thanks !   :)