Search code examples
kendo-uikendo-gridkendo-treelist

How to Get the Row Index of a Kendo TreeList Custom createChild Command


I have a Kendo TreeList that has the following custom commands:

{
    command: [
        {
            name: "Edit",
            imageClass: "fa fa-pencil"
        },
        {
            name: "Delete",
            imageClass: "fa fa-trash"
        },
        {
            name: "createChild",
            imageClass: "fa fa-plus"
        }
    ], title: "Actions", width: "300px"
}

I click the create child button, input my data and click "Update". This takes me to the "create" definition of my Kendo dataSource:

create: function (e) {//Called when the create child command is saved
    //Collect the data needed for the save
}

At this point I need to get the row index of the new row but I can't seem to find the right way to do that. I've tried things like:

$(e.target).closest("tr").parent().index()

But that gives -1

And:

var selectedRow = $scope.treelist.select();
var node = $scope.treelist.dataItem(selectedRow);

But node is undefined

Any ideas?


Solution

  • In fact you have no reference of the row into the create event's scope. However, you can find the element inside the widget's DOM:

    var index = $($("#grid").data("kendoTreeList").element).find(".k-grid-edit-row").index();
    

    The active editing row receives the k-grid-edit-row class and you can easily find it inside the widget's DOM tree.

    Working Demo.

    Not sure if is this what you really want.