lundi 31 août 2015

Stop Loading Nodes in Ajax Loading / Lazy Loading in JSTree

I am using JSTree with Ajax Loading / Lazy Loading functionality in my application.

Now I am trying to Open All nodes. So in Loaded event i write open_all method to open all nodes.

$('#DIVTree').jstree({
        'core': {
            'multiple': false,
            'data': {
                'url': appRootDir + 'Tree/GetFilterList',
                'data': function (node) {
                    return { 'ID': node.id};
                }
            }
        },
        'plugins': ['state'],
}).on('loaded.jstree', function (node) {
    $('#DIVTree').jstree(true).open_all();
});

Now this starts opening all node which i actually wanted.

But now i am having one more button Cancel.

I want to allow user to stop loading nodes when the cancel button is pressed.

I tried lots of ways. I tried to implement recursion with "after_open" event and "load_node" event.

$('#DIVTree').jstree({
        'core': {
            'multiple': false,
            'data': {
                'url': appRootDir + 'Tree/GetFilterList',
                'data': function (node) {
                    return { 'ID': node.id };
                }
            }
        },
        'plugins': ['state'],
}).on('loaded.jstree', function (node) {
        if (recrusiveStop == false) {
            OpenNodes();
        }
}).on('after_open.jstree', function (node) {
        if (recrusiveStop == false) {
            OpenNodes();
        }
});

var OpenNodes = function () {
    var nodeID = '';

    $('#DIVTree .jstree-closed').each(function () {
        if ($('#DIVTree').jstree(true).is_loaded(this.id) == false) {
            nodeID = this.id;
            return false;
        }
    });

    if (nodeID != '') {
        $('#DIVTree').jstree(true).open_node(nodeID);
    }
}

But still unable to implement.

In "after_open" event is fired only once. So only one node is expanded (not having sub-node) so not staying in loop. while i still want to expand siblings.

Is there any clear way to implement this?

I want to Open all nodes and also stop loading when user hits cancel button.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire