Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tkoning on Dec 18, 2008 02:28
open dhtmlx forum
Adding last node to tree

Hello,
When i try to add a node (nodelevel 1) to the last position of the dhtmlxtree component, it does not seem to add it to the tree.
When i add a node (nodelevel 1) to the dhtmlxtree component in any other position, it works just fine.

I am adding the new node as a sibling of the droptarget.

For adding the new node, i use the insertNewItem method (like some of the examples).

I am using the same method for both situations, the only diffirence is that the droptarget is the last existing node in the tree.

I do not get an error when trying to add the node to the last position, and when loading it through xml (when refreshing the page) it works just fine.

Is there any way to fix this problem?

Thanks,
Tkoning
Answer posted by Support on Dec 18, 2008 02:42
>>I am adding the new node as a sibling of the droptarget. 
>>For adding the new node, i use the insertNewItem method (like some of the examples).

There are two item adding methods in dhtmlxtree
     tree.insertNewItem - add item as child
     tree.insertNewNext - add item as sibling

So if you are using insertNewItem - you are adding new item as child of existing one, not as sibling.

Technically , there must not be any problem with adding new item at last position.( sample attached ) 
If issue still occurs for you - please provide any kind of sample where problem can be reconstructed. 
Attachments (1)
add_last.ZIP48.46 Kb
Answer posted on Dec 18, 2008 03:00
I'm sorry, I mistyped the function I used in my original question, I used insertNewNext for it, but when no node is selected, I use insertNewItem.
Both situations do not add a new node to the tree.

My tree structure is like this:
The rootnode is not displayed (nodelevel 0).
The nodes on level 1 can contain nodes of level 2.
The nodes on level 2 cannot contain nodes.

The following function is being called after a drag-in event and after a clickevent of a div.

function addComposite(drop_obj, source_id, target_on, target_before){
    if(target_on == null || target_on == 0){
        //no target is known, add node on level 1, to the last place in the tree.
        drop_obj.insertNewItem(0, newNodeId(), $(source_id).text);
        //phpAddQuestion(-1, 0, 6, 0);
    }else{

        if(drop_obj.getLevel(target_on) == 1){
            //droptarget is of level 1.
            drop_obj.insertNewNext(target_on, newNodeId(), $(source_id).text);

            //phpAddQuestion(-1, tree.getUserData(target_on, "questionid"), 6, 0);
        }
    }

}

Can you reconstruct the problem with this?

Thank you.

Answer posted by Support on Dec 18, 2008 03:23
Please be sure that you code branches with insertNewItem or insertNewNext commands are realy executed - the code looks correct and must not cause any problems. 
Also, please be sure that newNodeId() returns unique values. 


Answer posted by Tkoning on Dec 18, 2008 04:12
The code executes the insertNewNext and insertNewItem, but does not add the node. I have checked this by adding an alertbox inside these functions.

The newNodeId() function returns a unique nodenumber (incremental by looking at existing nodes).
Answer posted by Support on Dec 19, 2008 06:13
Unfortunately issue still can't be reconstructed, if it still appears for you - please provide any kind of sample or demo link where issue can be reconstructed. 
You can send such info directly to support@dhtmlx.com 
Answer posted by Tkoning on Jan 09, 2009 04:42
After some testing, i found out that this is being caused by loading the treedata by json (through a php script that is being called with loadJSON() function).
When i leave the loadJSON out, and insert a few items into the tree (using insertNewItem function), and then drag new items in the tree, it works correctly.

I am using the standard version currently, could it be that only the professional version supports the json format properly?

Thanks.
Answer posted by dhxSupport on Jan 09, 2009 08:10
The issue was confirmed for standard version ( somehow pro version doesn't affected ) 
Fix will be released as part of next build, if you need it ASAP - please contact us directly at support@dhtmlx.com