Search code examples
javascriptphpjqueryjstree

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


Solution

  • 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"
            }
        }
    });