Home > front end >  Kendo grid - Get current row on checkbox click event
Kendo grid - Get current row on checkbox click event

Time:05-02

I have a kendo grid with multiple checkbox per row. when a user checks/uncheck one of them, I have to get other(adjacent) checkbox values and determine if the combination is valid. Grid

columns.Bound(c => c.AnswerB).Title("B").Width(80).ClientTemplate("<input id='AnswerB' name='chkB' class='checkbox' type='checkbox' value='#=AnswerB#' # if (AnswerB) { # checked='checked' # } # onclick='onAnswerClick(this)'/>");
columns.Bound(c => c.AnswerC).Title("C").Width(80).ClientTemplate("<input id='AnswerB' name='chkC' class='checkbox' type='checkbox' value='#=AnswerC#' # if (AnswerC) { # checked='checked' # } # onclick='onAnswerClick(this)'/>");

function onAnswerClick(me) 
{
    var grid = $("#AnswersGrid").data("kendoGrid");
    var row = $(this).closest("tr");
    var dataItem = grid.dataItem(row);
    console.log(row)
    console.log(dataItem) <---- Is Null

}

I cannot seem to get the row when the checkbox is changed. Thanks for any help!

CodePudding user response:

Managed to get it working by attaching change event to the grid instead of onClick on each column

    $('#AnswersGrid').on("change", "input", function (e) {
    var grid = $("#AnswersGrid").data("kendoGrid");
    grid.select($(this).closest('tr'));
    var checked = $(this).is(':checked');
    var row = $(e.target).closest("tr");
    var item = grid.dataItem(row);
    var col = $(this).closest('td');
    console.log(row);
    console.log(item.AnswerB)
    });
  • Related