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

Node fields not updating on drop

2 Answers 43 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 10 Mar 2020, 03:37 PM
What I am trying to accomplish: After dragging an element I am sending node info (for all elements) to the server so the records can be created for user preferences. 

It works fine but... changes to elements do not take affect until the second drop. So, If i drag a root node (say folder1) into another root node (say folder2), under my logic below the parent of folder1 still does not exist. However.. if I drop folder1 onto folder2 a second time the parent then exists. So, ultimately how would I ensure that my logic runs for the changes after the drop?

Thanks in advance.

 

Snippet of my JavaScript:

 $("#div_tree").kendoTreeView({

                    dataSource: data.ProDataSet["treemenu"],
                    dragAndDrop: true,
                    drop: function(e){                     
                         updatePinPreferences();
                    }             
  }); 
 
function checkedNodeIds(nodes,docarray) {
            for (var i = 0; i < nodes.length; i++) {
                                  
                 try{
                       var parent = treeView.parent(treeView.findByText(nodes[i].text));
                       console.log(nodes[i].text + " | " + nodes[i].index + " | " + nodes[i].itemtype + " | " + icount + " | " + treeView.text(parent) );
                  }
                  catch(e){
                      console.log("CANNOT FIND PARENT " + nodes[i].text ,e);
                      parentName = "";
                  }
                
 
                if (nodes[i].hasChildren) {
                    checkedNodeIds(nodes[i].children.view(),docarray);
                }
            }
        }
}
         
function updatePinPreferences() {
    var treeView = $("#div_tree").data("kendoTreeView"),
        message;
 
    checkedNodeIds(treeView.dataSource.view(), jdoc);
}

 

2 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 12 Mar 2020, 01:47 PM

Hello Tyler,

The "drop" event fires immediately after a node is dropped, thus, in your example when it fires folder1 is not yet a child of folder2. Consider executing your logic after a small delay. This would allow the dropped node to be actually added as a child of the node it is dropped over. Here's an example: https://dojo.telerik.com/IToFIpUV/2

updatePinPreferences is called after a small delay in the drop event handler. Additionally, I declared jdoc and icount before checkedNodeIds function and I added:

var treeView = $("#div_tree").data("kendoTreeView");

before:

var parent = treeView.parent(treeView.findByText(nodes[i].text));

"parent" does not work only for the Furniture node, which is at the root level, thus it does not have a parent node.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Tyler
Top achievements
Rank 1
answered on 16 Mar 2020, 01:50 PM

Excellent response Ivan, exactly what I was looking for.

Thank you for your time,

Tyler

Tags
TreeView
Asked by
Tyler
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Tyler
Top achievements
Rank 1
Share this question
or