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

Finding cell by column for selected row

3 Answers 443 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 01 Feb 2017, 06:44 PM

Each of our treelists contains an Id column that uniquely identifies the row's object.  Our first implementation was rather straightfoward in that we simply got the Id from what we know is the correct column (based on static column ordering):

 

var row = $(event.currentTarget).closest("tr");
var versionId = parseInt(row[0].cells[1].childNodes[1].data);

 

However, since our users are able to reorder the columns, we're unable to hard-code the cell in order to find the Id of the selected row.

Given a row, how do we find which column is the "Id" column?

3 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 01 Feb 2017, 07:02 PM

Found it -- focusing on the Kendo object vs. the jQuery object will make it easier!  (In the example below, 'ROOTID' is the column that contains the unique Id for the row.)  However, if the user is able to hide the Id column (and does so!), this will fail.

 

var treelist = $("#AttachmentsTreeList").data("kendoTreeList");
var columnIdx = 0;
 
for (i = 0; i < treelist.columns.length - 1; i++){
    if (treelist.columns[i].field == 'ROOTID')
    {
        columnIdx = i;
        break;
    }
}
0
Matt
Top achievements
Rank 1
answered on 03 Feb 2017, 01:55 AM

And an even better way...simply use the target field (in our case:  ROOTID) to get the value you're seeking:

function cogActions(sender){
 
    var treelist = $("#AttachmentsTreeList").data("kendoTreeList");
    var versionId = treelist.dataItem($(sender.target).closest("tr")).ROOTID
 
}

 

NOTE:  sender is an icon embedded in one of the cells of the treelist

0
Stefan
Telerik team
answered on 03 Feb 2017, 01:06 PM
Hello Matt,

I'm glad to hear that the issue is resolved.

We greatly appreciate sharing the solution with the Kendo UI community.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
TreeList
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or