Search code examples
javascripthtmlevent-handlingkendo-treelist

How to get the dataitem from e.target in the onDrag method of a Kendo TreeList (in Javascript)?


I have an onDrag method bound to the drag-event of a treeList. In this method, I need to get the dataitem in the tr the user drags over. But e.target only gets the td element.

exportObject.onDrag = function (e) {

    console.log(e.target); //output is td element
    //console.log(e.target.parentElement); //undefined
    console.log(this); //same as e.target
    //if(e.target.?ROW.DATAITEM?.SomeProp != "something") e.setStatus("k-i-cancel");
};

Solution

  • This feels like cheating, but if people searches and lands here, I make an answer here as well: To get a hold of dataItem in drag event I use a ugly piece of code:

    $(e.target).parents('.k-treelist').data('kendoTreeList').dataItem(e.target)
    

    But as long as it's working!