This is a migrated thread and some comments may be shown as answers.
Custom checkbox editor for boolean values
1 Answer 86 Views
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 16 Jan 2017, 10:42 AM

Hello,

I tried to create a custom cell editor for boolean values in a grid by adding the k-checkbox style to a checkbox.
Unfortunately it doesn't seem to work. When clicking on the styled checkbox, the cell just closes the edit mode, but doesn't change the value.

Is there a solution for this problem?

Thank you for your help,
Daniel

1 Answer, 1 is accepted

Sort by
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 18 Jan 2017, 10:40 AM
Hello Daniel,

The recommended approach for checkbox templates within the Kendo UI Grid is to keep them in a template column without binding them to the boolean field from the model.

To keep the data source updated, attach an event handler to the change event of the checkboxes. Then, in the event handler function, update the relevant dataItem with a call to the set() method:

$("#grid .k-grid-content").on("change", "input.k-checkbox", function(e) {
  var grid = $("#grid").data("kendoGrid"),
  dataItem = grid.dataItem($(e.target).closest("tr"));
  dataItem.set("Discontinued", this.checked);
});

I have modified one of our demos to feature the checkboxes for your convenience at:

http://dojo.telerik.com/Ufoca

Regards,
Alex Hajigeorgieva
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
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or