Gabriele Pieretti
Gabriele Pieretti

Reputation: 161

JSTree - Disable automatic selection of children on load

I need to disable the automatic selection of all children at loading time. If I set a parent node with selected parameter to true, it will select all of its children, but I want to have only the parent node selected.

$('#tree_groups').jstree({
        'plugins': ["wholerow", "checkbox", "types"],
        'core': {
            'data': [{
                "id": "0-14089749041",
                "text": "Sport",
                "state": {
                    "selected": true,
                },
                "children": [{
                "id": "14089749041-14089751330",
                "text": "Pallacanestro",},
                {"id": "14089749041-14089751110",
                "text": "Tennis",},
            ]},
        "types" : {
            "default" : {
                "icon" : "fa fa-group icon-state-warning icon-lg"
            },
            "file" : {
                "icon" : "fa fa-file icon-state-warning icon-lg"
            }
        }
    });

Thanks

Upvotes: 5

Views: 4159

Answers (2)

Bojan Vukajlovic
Bojan Vukajlovic

Reputation: 36

I have looked for article which contains proper answer on this problem. This can be solved on easiest possible way. On jstree instance just add an event as i showed below

.on('changed.jstree', function (e, data) {
    if (data.event === undefined) return false;
})

Upvotes: 0

Gabriele Pieretti
Gabriele Pieretti

Reputation: 161

I found the answer by myself, I've just set the three_state of checkbox plugin to false.

$('#tree_groups').jstree({
    'plugins': ["wholerow", "checkbox", "types"],
    'core': {
        'data': [{
            "id": "0-14089749041",
            "text": "Sport",
            "state": {
                "selected": true,
            },
            "children": [{
            "id": "14089749041-14089751330",
            "text": "Pallacanestro",},
            {"id": "14089749041-14089751110",
            "text": "Tennis",},
        ]},
    "checkbox" : {
            "three_state" : false,
        },
    "types" : {
        "default" : {
            "icon" : "fa fa-group icon-state-warning icon-lg"
        },
        "file" : {
            "icon" : "fa fa-file icon-state-warning icon-lg"
        }
    }
});

Upvotes: 7

Related Questions