Search code examples
javascriptbuttoncheckboxkendo-uikendo-ui-grid

Uncheck checkbox in same row kendo grid at button press


I have a Kendo Grid with multiple columns.

@(Html.Kendo().Grid<GridViewModel>()
                  .Name("Docgrid")
                  .Columns(columns =>
                  {
                      columns.Bound(c => c.read).Template("<input type='checkbox' #= IsUnread ? checked='checked': '' # class='chkbx' />");
/* some more columns */
                      columns.Command(cmd =>{cmd.Custom("Download").Click("download");});

When I press the Downloadbutton I want to unselect the checkbox in the same grid row.

right now I only managed to unselect all checkboxes

Check/uncheck a checkbox in the table row when any checkbox in the same row is clicked I found this but I wasn't able to adapt it to my needs using a button.

 $("#Download").click(function () {
    $("input[type='checkbox']").prop('checked', false);
});

Solution

  • Try this:

    $(this).closest("tr").find("input[type='checkbox']").prop('checked', false);
    

    This code will select any checkbox in the button#download row. Demo below:

    $("#download").click(function () {
        $(this).closest("tr").find("input[type='checkbox']").prop('checked', false);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table>
      <tr>
        <td>
          <input type="checkbox" checked="checked">
        </td>
        <td>
          <button type="button" id="download">Download"</button>
        </td>
      </tr>
    </table>

    In the demo I used an ordinary table, but it should work in a Kendo table as well. Make sure to change the input[type='checkbox'] selector in case you want to change only one checkbox in the same row.