EasyUI Forum
May 10, 2024, 08:25:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Lazy load in Tree (not in treeGrid)  (Read 10028 times)
amir-t
Newbie
*
Posts: 48


View Profile
« 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
« Last Edit: July 22, 2013, 07:11:16 AM by amir-t » Logged
amir-t
Newbie
*
Posts: 48


View Profile
« Reply #1 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 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
});
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!