Finding cell by column for selected row

4 posts, 0 answers
  1. Matt
    Matt avatar
    87 posts
    Member since:
    Mar 2009

    Posted 01 Feb Link to this post

    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?

  2. Matt
    Matt avatar
    87 posts
    Member since:
    Mar 2009

    Posted 01 Feb in reply to Matt Link to this post

    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;
        }
    }
  3. Matt
    Matt avatar
    87 posts
    Member since:
    Mar 2009

    Posted 02 Feb Link to this post

    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

  4. Stefan
    Admin
    Stefan avatar
    1040 posts

    Posted 03 Feb Link to this post

    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 visualization (charts) and form elements.
Back to Top