Lazy loading in Jstree3.0

601 views
Skip to first unread message

nishant gupta

unread,
Mar 18, 2014, 3:13:37 AM3/18/14
to jst...@googlegroups.com
Hi,

I want to apply lazy loading in JStree. Right now i am loading full tree single time but i have more then 1 lakh records so it is taking time.
So i want to load root nodes first and on expand of nodes i want to load child.
current code i am using

$('#jstreeDiv').jstree({
            'core': {
                "themes": {
                    "stripes": true,
                    "icons": false
                },
                'data': {
                    'url': '/User/GetEntitlement',
                    'data': function (node) {
                        return { 'id': node.id };
                    }
                }
            },
            "checkbox": {
                "keep_selected_style": false
            },
            "plugins": ["checkbox", "types"]
        })

This code is loading full tree first time only. So please let me know how can i do load on demand.

Thanks,
Nishant

Ivan Bozhanov

unread,
Mar 18, 2014, 3:22:12 AM3/18/14
to jst...@googlegroups.com
Once again - the same answer I gave you in the personal email:
Your config is OK, modify the data you return - the JSON that get returned from /User/GetEntitlement probably contains (as you have not shown any part of it) a list of nodes who have "children" properties, which in turn are arrays of objects, so you basically should have something like:
[{ "text" : "Root node 1", "children" : [ {...}, {....} ] }, { "text" : "Root node 2", ... }]

In all the nodes that you want lazy loaded, replace the children array with boolean true:
[{ "text" : "Root node 1", "children" : true }, { "text" : "Root node 2", ... }]

That is all ... and it is also available in the docs, and the only example on jstree.com features exactly this.

Best regards,
Ivan

P.S. I wish we could appreciate each other's time and avoid asking the same basic questions over all possible communication channels.

nishant gupta

unread,
Mar 18, 2014, 6:44:46 AM3/18/14
to jst...@googlegroups.com
Thanks Ivan. I got it now what you were saying and is working fine.

Thanks,
Nishant


--
You received this message because you are subscribed to a topic in the Google Groups "jsTree" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jstree/Bet7P_xPM9k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jstree+un...@googlegroups.com.
To post to this group, send email to jst...@googlegroups.com.
Visit this group at http://groups.google.com/group/jstree.
For more options, visit https://groups.google.com/d/optout.

nishant gupta

unread,
Mar 19, 2014, 3:31:19 AM3/19/14
to jst...@googlegroups.com
Thanks Ivan, Hope you are doing good.
Lazy Loading is working perfectly as expected But, there is small issue i am facing here that some of the nodes can have the selected child along with un-selected.
Which we can not come to know till we reach leaf node.
So I want to make user aware at root level that there is some selected child exists. How to achieve this kindly suggest.

Can I send some property from my model to tell the node is fully selected or Partially selected(undetermined).

How can I change css class of a node.I can find in older version it can be achieve as below:
json_data: {
        ajax: {
            url: '/api/group/node',
            success: function (groups) {
                var nodes = [];
                for (var i=0; i<groups.length; i++) {
                    var group = groups[i];

                    var cssClass = "";
                    if(group.isSelected)
                        cssClass = "jstree-checked";
                    else if(group.isDecendantSelected)
                        cssClass = "jstree-undetermined";

                    nodes.push({
                        data: group.name,
                        attr: { 'class': cssClass }
                    });
                }
                return nodes;
            }
        }
    }
Please let me know how can we achieve same in Jstree3.0

Thanks,
Nishant

Ivan Bozhanov

unread,
Mar 19, 2014, 9:44:47 AM3/19/14
to jst...@googlegroups.com
If the node should be selected - simply mark it as selected in the data using the "state" property (and the "selected" property inside state). If it should be undetermined - set "state.undetermined" to true.

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages