This is a migrated thread and some comments may be shown as answers.

TreeView insertAfter/insertBefore not doing anything

4 Answers 274 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Miika
Top achievements
Rank 1
Miika asked on 22 Mar 2013, 01:24 PM
Hi there,

I've got a problem with inserting new nodes into the TreeView. The context is that I am doing drag and drop operations from one tree to another, and I want the action to be a copy rather than move, so I need to e.preventDefault the action and handle the copying myself (see issue: http://www.kendoui.com/forums/ui/treeview/re-two-trees----allowing-the-drop-but-preventing-the-draggable-from-moving.aspx) . This is fine, I thought I had it working, as the "over" part of the code works just fine, using .append.

However, it would seem that insertBefore and insertAfter simply don't do anything. Most likely I am doing something wrong, but I can't figure out what. See below the code for all three actions, (data is an object returned from ajax call fitting the schema of the tree).

if (e.dropPosition == 'before') {
    theOtherTree.insertBefore(data, $(e.dropTarget));
}
else if (e.dropPosition == 'over') {
    theOtherTree.append(data, $(e.dropTarget));
}
else if (e.dropPosition == 'after') {
    theOtherTree.insertAfter(data, $(e.dropTarget));
}

There is no error throw, the insert functions simply do nothing. The append function works just fine. Any thoughts?

4 Answers, 1 is accepted

Sort by
0
Miika
Top achievements
Rank 1
answered on 25 Mar 2013, 07:50 AM
I was using version 2012.2.913, but the updating to 2013.1.319 still gives me the same problem. insertAfter and insertBefore don't appear to do anything.
0
Miika
Top achievements
Rank 1
answered on 25 Mar 2013, 08:18 AM
Testing further with the latest version, it seems that insertAfter actually does add the object, except it is added to the bottom of the tree (and nowhere close to the actual dropTarget element). I did not see it before because my target tree was larger than the screen.
0
Accepted
Alex Gyoshev
Telerik team
answered on 26 Mar 2013, 08:11 AM
Hello Miika,

The problem that you encountered is that insertBefore/insertAfter expect the second parameter to point to a .k-item (<li>) element, and it points to the nested <div> of the element. You can work around this by using jQuery.fn.closest, like shown in this jsBin sample. We understand that this behavior is unexpected, so we will improve the methods to call closest internally, starting from the next internal build.

Kind regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Miika
Top achievements
Rank 1
answered on 26 Mar 2013, 08:57 AM
That appeared to be the problem. Works just fine now when using closest k-item from dropTarget. Thank you!
Tags
TreeView
Asked by
Miika
Top achievements
Rank 1
Answers by
Miika
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or