Setting "id" while creating new node

1,863 views
Skip to first unread message

Mohammad Zakir Hussain

unread,
Jun 25, 2016, 12:56:07 PM6/25/16
to jsTree
Sir Alejandro,

How can i set "id" while creating a new node, Because id i would like to type cast to integer for my transaction table.

Thanks in advance...

Regards,
Mohammad

Alejandro Grigera

unread,
Jun 25, 2016, 4:05:00 PM6/25/16
to jsTree
First, dont direct the questions  to me, I'm just a user like you with some experience trying to help.
Second you can specify the ID of a new node if you use the create_node function or if you let jstree assign an ID you can change it later with set_id function.

Best regards

Mohammad Zakir Hussain

unread,
Jun 26, 2016, 4:03:26 AM6/26/16
to jsTree
Dear Alejandro,
I'm extremely sorry for addressing you directly i thought you are one of the team member of JSTree and 
Thank you for sharing your knowledge and experience with us, actually no one does it in this materialistic world...

Thanks & Best Regards,
Mohammad

Mohammad Zakir Hussain

unread,
Jun 27, 2016, 10:52:06 AM6/27/16
to jsTree
hi Alejandro,

Greetings of the day!

Sorry for directly putting this question to you...

I am not able to create node with the following code, Please help

$('button').on("click", function () {
 $("#container1'").jstree('create_node', 'AAA', {'id' : '1944', 'text' : 'BBB'}, 'last');
 $("#container1").jstree({"core" : {"check_callback" : true}});
   });  


Regards,
Mohammad

Alejandro Grigera

unread,
Jun 27, 2016, 11:29:26 AM6/27/16
to jsTree
Ok, this is how I would do it:

$("#container1").jstree({    //First create the tree
    "core" : {
        "check_callback" : true
    }
 }).on('ready.jstree', function(){    //Same time create an event that will run when the tree is ready
        $('#container1').jstree().create_node('AAA', {'id' : '1944', 'text' : 'BBB'}, 'last');    //When we know for sure the tree is ready, we create the nodes we want
});;


Best regards

Mohammad Zakir Hussain

unread,
Jun 27, 2016, 11:41:18 AM6/27/16
to jsTree
hi,

I'm able to generate tree, but when i try to create node on button click its not happening anything. Please help.


<script>
$(function() {
$('#container1').jstree({
   'core' : {
       "animation" : 0,
       "check_callback" : true,
       "themes" : { "stripes" : true },
      'data' : [{"id":"Celulares","text":"Celulares","parent":"#"},
                {"id":"AAA","text":"AAA","parent":"Celulares"},
                {"id":"FamilyNames","text":"FamilyNames","parent":"#"},
                {"id":"DDD","text":"DDD","parent":"FamilyNames"},
                {"id":"CCC","text":"CCC","parent":"#"}
                ]
},
"plugins" : [ "dnd", "contextmenu", "massload", "search", "unique"]
});

$('button').on("click", function () {
 $("#container1'").jstree('create_node', 'AAA', {'id' : '1944', 'text' : 'BBB'}, 'last');
 $("#container1").jstree({"core" : {"check_callback" : true}});
   });  
   });
</script>


Thanks in advance...

Regards,
Mohammad



Mohammad Zakir Hussain

unread,
Jun 27, 2016, 1:38:54 PM6/27/16
to jsTree
Thanks Alejandro, I found the solution to my problem and its working fine now....
Reply all
Reply to author
Forward
0 new messages