evilom
evilom

Reputation: 583

kendo ui treeview dragend get node id

I have this function to catch the drag end event of a kendo treeview

function onDragEnd(e) {
 console.log("Drag end", e.sourceNode, e.dropPosition, e.sourceNode);
}

this displays the whole node data such as

<li role="treeitem" class="k-item k-last" data-uid="[some guid]">
   <div class="k-bot">
      <span class="k-in">[node text]</span>
   </div>
</li>

there is also this function to get the text of the node.

var text = this.text(e.sourceNode);

i was hoping that something like

var id = this.id(e.sourceNode);

would work but it didn't,

Upvotes: 2

Views: 2900

Answers (1)

tsacodes
tsacodes

Reputation: 360

TreeView

$("#treeView").kendoTreeView({
    dragAndDrop: true,
    dataSource: treeViewDataSource,
    dataTextField: "Name",
    dragend: function(e) {
        var tree = $(#treeView).data("kendowTreeview");

        /* tree.dataItem accesses the item's model. You will be able to
         access any field declared in your model*/

        var movingItem = tree.dataItem(e.sourceNode);
        var destinationItem = tree.dataItem(e.destinationNode);

        /*Using firebug, console.log(movingItem) will elaborate better 
        as to what you have access in the object*/

        var movingItemID = movingItem.id;
        var destinationItemID = destinationItem.id;
        //Get the same ID by movingItemID.MyID 
        //(if id:"MyID" set in dataSource's schema)
    }
});

Upvotes: 5

Related Questions