EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: amir-t on July 22, 2013, 07:09:41 AM



Title: Lazy load in Tree (not in treeGrid)
Post by: amir-t on July 22, 2013, 07:09:41 AM
Hi,
Is there a way to implement lazy loading nodes in the tree component when we have full hierarchic tree data?

I've tried to use the linked example (where the lazy loading is implmeneted for treeGrid)
in the easyui tree component but for some reason, the property of "children1" is being removed, and when the callback of opts.onBeforeExpand is called, the row doesn't have this propery,
although it was created at the setData logic.

I used this example and tried to reuse it in the tree component:
http://www.jeasyui.com/tutorial/tree/treegrid5.php


Title: Re: Lazy load in Tree (not in treeGrid)
Post by: amir-t on July 24, 2013, 09:52:58 AM
Hi,
i still didn't managed to solve this problem,
hope you'll be able to assist as soon as possible.

Thanks


Title: Re: Lazy load in Tree (not in treeGrid)
Post by: stworthy on July 28, 2013, 03:47:30 AM
Define the 'loadFilter' function as below.
Code:
function loadFilter(data,parent){
    function setData(){ 
        var todo = []; 
        for(var i=0; i<data.length; i++){ 
            todo.push(data[i]); 
        } 
        while(todo.length){ 
            var node = todo.shift(); 
            if (node.children){ 
                node.state = 'closed'; 
                node.attributes = {
children: node.children
};
                todo = todo.concat(node.children); 
                node.children = undefined; 
            } 
        } 
    } 
setData();
var t = $(this);
var opts = t.tree('options');
opts.onBeforeExpand = function(node){
if (node.attributes && node.attributes.children){
var filter = opts.loadFilter;
opts.loadFilter = function(data){return data};
t.tree('append',{
parent: node.target,
data: node.attributes.children
});
opts.loadFilter = filter;
}
};
return data;
}

Apply this function to a tree component.
Code:
$('#tt').tree({
  loadFilter: loadFilter
});