EasyUI Forum
September 14, 2025, 03:38:10 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Tree grid - loading expanded node data with loader property  (Read 18557 times)
amir-t
Newbie
*
Posts: 48


View Profile
« 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}
]
« Last Edit: July 14, 2013, 10:17:03 AM by amir-t » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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}
]
Logged
amir-t
Newbie
*
Posts: 48


View Profile
« Reply #2 on: July 15, 2013, 01:04:08 AM »

Hi,

i tried your advice, but still doesn't work  Sad

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);   
             }
        }
});
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: July 15, 2013, 01:22:45 AM »

Please refer to this example http://jsfiddle.net/dvAcu/.
Logged
amir-t
Newbie
*
Posts: 48


View Profile
« Reply #4 on: July 15, 2013, 03:55:05 AM »

Works fine now.
thanks !   Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!