I want to create a new child as first item below a parent. For this I can use neither insertNewChild nor insertNewNext.
The only workaround that comes to mind is creating the child and then moving it to the top with moveItem. But the moveItem function is also quite stupid.
How about a method where I can pass an index of the position where my new/moved item should go?
The only workaround that comes to mind is creating the child and then moving it to the top with moveItem.
It is right way.
It is not.
insertNewChild inserts it as last child and insertNewNext inserts as next sibling after a specified item.
But the moveItem function is also quite stupid.
Why do you think so?
Because move “up” doesn’t always move up. It could also move the item to a totally different level if the item before it happens to have children and is open. You have to use “up_strict” if you want to do that. And the modes are not even documented (listed, but not explained) in the API on docs.dhtmlx.com/doku.php?id=dhtm … t_moveitem . You only find it if you read through all pages but not if using the API as a reference.
The easiest would be to call moveItem with the parent id and an index of the new position within the children of the parent. But you preferred to invent 8 different modes which work not intuitively at all.
[code]var parentId = “…”;
var newId=(new Date()).valueOf();
var id = tree.getItemIdByIndex(parentId ",0);
if(id){
tree.insertNewNext(id,newId,“Item text”);
tree.moveItem(newId,“up_strict”);
}
else{
tree.insertNewChild(parentId ,newId,“Item text”);
}
If there are any children use insertNewNext() and replace items.
If there is no children - just insertNewChild()
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan