vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.13k stars 1.39k forks source link

Node Position Sequence #2765

Closed taryono closed 1 week ago

taryono commented 7 months ago

I Have One Menu and Five childrens like this

{ id:1, text: "Sub Nodes", icon: "fa fa-folder text-danger", children: [ { id:2,text: "Item 1", icon: "fa fa-folder text-waring" }, { id:3,text: "Item 2", icon: "fa fa-folder text-success" }, { id:4,text: "Item 3", icon: "fa fa-folder text-default" }, { id:5,text: "Item 4", icon: "fa fa-folder text-danger" }, { id:6,text: "Item 5", icon: "fa fa-folder text-info" }, ], }, When I move the children Item 1 to the last position I get the posistion is 5, but when I move it as First children I get the position is 0

I try to add console.log(pos) in jstree.js line 4188

console.log('pos',pos)

switch(pos) { case "before": pos = $.inArray(par.id, new_par.children); break; case "after" : pos = $.inArray(par.id, new_par.children) + 1; break; case "inside": case "first": pos = 0; break; case "last": pos = new_par.children.length; break; default: if(!pos) { pos = 0; } break; }

then I inspect element -> console I see pos 0 , pos 1, pos 2 etc...

sorry I just try it and I revert it back

Thanks

vakata commented 1 week ago

Use the events that happen AFTER the move is completed - you will get a correct index there.