Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change jstree node text colour based on type

I have been searching the interent for an age and couldnt find an answer. I was trying to change node text colour dependant on the type of the particular node. So in this example i wanted to change the text colour of every node that is a "Role" type defined in data.

    $("#roleTree").jstree({
        json_data: {
            data: roleTreeData
        },
        "themes": {
            "theme": "default",
            "dots": true,
            "icons": false
        },
        "ui": {
            "select_limit": 1,
            "select_multiple_modifier": "none"
        },
        "types": {
            "types": {
                "AM": {
                    "hover_node": false,
                    "select_node": false
                },
                "AF": {
                    "hover_node": false,
                    "select_node": false
                },
                "Role": {
// i dont know if possible to be done here? add class?
             //   this.css("color", "red")
                    //{ font-weight:bold}
                }
            }
        },

        plugins: ["themes", "json_data", "ui", "Select", "types", "crrm"]

    }).bind("loaded.jstree", function (event, data)
    {
        $("#roleTree").jstree("open_all");
         data.inst.select_node('ul > li:first');

    }).bind("select_node.jstree", function (event, data)
    {
        selectedRoleId = data.rslt.obj.attr("id");
        window.selectedRole = GetRole(selectedRoleId);              
    });
}

Or any other method to highlight or tell users that only the role is selectable.

like image 244
user1358918 Avatar asked Aug 08 '12 08:08

user1358918


1 Answers

This can be done using the following CSS, assuming you are using the default classic theme.

.jstree-classic li[rel="Role"] > a { color:red; }

Get jstree-classic class, where child li has rel attribute of Role, get the first child a of that li and assign color to red.

like image 52
Bojin Li Avatar answered Sep 30 '22 06:09

Bojin Li