Change jstree node color programmitically

7,100 views
Skip to first unread message

vishal yagnik

unread,
May 26, 2014, 10:22:34 AM5/26/14
to jst...@googlegroups.com

My jstree bind with following json format comes from web service..i want to change node color programmatically.

is there any property for this.?


   $("#divCourseTree").jstree({
                 'core': {
                     'data': {
                         'type': "POST",
                         "async": "true",
                         'contentType': "application/json; charset=utf-8",
                         'url': "../WebService/BranchLocation.asmx/BindCourseTreeData",
                         'data': "{}",
                         'dataType': 'JSON',
                         'data': function (node) {


                         }
                     }
                 }
             });


json output :

{ "id": "ajson1", "parent": "#", "text": "Simple root node"}, { "id": "ajson2", "parent": "#", "text": "Root node 2" }, { "id": "ajson3", "parent": "ajson2", "text": "Child 1" }, { "id": "ajson4", "parent": "ajson2", "text": "Child 2" },

Ivan Bozhanov

unread,
May 26, 2014, 3:41:46 PM5/26/14
to jst...@googlegroups.com
Use a class in "li_attr" and apply any styles you wish by using that class.

Best regards,
Ivan

vishal yagnik

unread,
May 27, 2014, 6:18:44 AM5/27/14
to jst...@googlegroups.com
    $("#divCourseTree").jstree({
                     'core': {
                         'data': {
                             'type': "POST",
                             "async": "true",
                             'contentType': "application/json; charset=utf-8",
                             'url': "../WebService/BranchLocation.asmx/BindCourseTreeData",
                             'data': "{}",
                             'dataType': 'JSON',
                             'data': function (node) {
                                
                              },
                             'success': function (retvel) {
                                 var r = [];
                                 var data = eval("(" + retvel.d + ")");
                                 for (var key in data) {
                                     if (data.hasOwnProperty(key)) {
                                       
                                         var y = data[key].id;
                                         r.push(y);
                                         $("#" + y + " a").addClass('.Selected');
                                       
                                     }
                                 }
                               
                             }

                         }
                       }
                     });

its not working.. please help

Ivan Bozhanov

unread,
May 27, 2014, 11:09:13 AM5/27/14
to jst...@googlegroups.com
Sorry, I have no idea what you are doing ... read my previous post ... I told you to use the li_attr property of your JSON node, I have no idea what you are trying to achieve with addClass ...

Ivan Bozhanov

unread,
May 27, 2014, 11:11:05 AM5/27/14
to jst...@googlegroups.com
It has to be set in your data, not in a success callback ... in your data include something like:
{ "id" : "node1", "text" : "Some example node", "li_attr" : { "class" : "red" }, ...

Then in your CSS:
.red { background:red !important; }

Best regards,
Ivan


27 май 2014, вторник, 13:18:44 UTC+3, vishal yagnik написа:
Message has been deleted

ashish maheshwari

unread,
Mar 18, 2019, 7:57:37 AM3/18/19
to jsTree
this li_attr class setting gets reverted  on clicking another row in  the jstree. any fix for this 
i am updating json object and recreating jstree on page but still no use
Reply all
Reply to author
Forward
Message has been deleted
0 new messages