I've created the following editable grid bound to a model. The Date and Integer EditorTemplates work just fine.
However, our user case requires that we multi-select via a checkbox, which is why I added a Selected boolean in the Model. I'd rather cycle through these via the grid's data than by iterating through [tr]s, as it is a much cleaner way to do so.
Via a custom Checkbox EditorTemplate and the ClientTemplate I'm able to successfully display a checkbox. However, I have tried many ways to bind it to the actual Model property and have failed each time. I've tried @HTML.CheckboxFor and @HTML.Checkbox within my EditorTemplate, the latter working properly but not binding to the Model. The CheckboxFor throws a message about not being able to bind a null value... I've tried bool?, bool and System.Boolean, but all three would not bind properly.
View
Model
However, our user case requires that we multi-select via a checkbox, which is why I added a Selected boolean in the Model. I'd rather cycle through these via the grid's data than by iterating through [tr]s, as it is a much cleaner way to do so.
Via a custom Checkbox EditorTemplate and the ClientTemplate I'm able to successfully display a checkbox. However, I have tried many ways to bind it to the actual Model property and have failed each time. I've tried @HTML.CheckboxFor and @HTML.Checkbox within my EditorTemplate, the latter working properly but not binding to the Model. The CheckboxFor throws a message about not being able to bind a null value... I've tried bool?, bool and System.Boolean, but all three would not bind properly.
View
@(Html.Kendo().Grid(Model.ExtensionDetails) .Name("ExtensionInfoGrid") .Columns(columns => { columns.Bound(o => o.Selected) .Title("") .Width(50) .ClientTemplate("<input type='checkbox' id='isSelected' name='isSelected' #if(Selected){#checked#}# value='#=Selected#' />") .EditorTemplateName("Checkbox"); columns.Bound(o => o.ExtendFromDate) .Title("Extend From Date *") .Width(150) .Format("{0:M/d/yyyy}") .Filterable(false) .Sortable(true) .EditorTemplateName("Date"); columns.Bound(o => o.Units) .Title("Units *") .Width(100) .EditorTemplateName("Integer"); columns.Bound(o => o.UnitType).Title("Unit Type"); }) .Editable(editable => editable.Mode(GridEditMode.InCell)) .DataSource(dataSource => dataSource .Ajax() .ServerOperation(false) .Model(model => { model.Id(m => m.Code); model.Field(m => m.Selected).Editable(true); model.Field(m => m.ExtendFromDate).Editable(true).DefaultValue(DateTime.Now); model.Field(m => m.Units).Editable(true); model.Field(m => m.UnitType).Editable(false); }) ))}using System;using System.Collections;using System.Collections.Generic;using System.Linq;using ProviderWebAppMVC.UmServiceRef;namespace ProviderWebAppMVC.Models{ public class ExtensionDetail { public ExtensionDetail() { Selected = true; Code = string.Empty; Description = string.Empty; ExtendFromDate = DateTime.Now; ExtendToDate = DateTime.Now; Units = 0; UnitType = string.Empty; } public bool Selected; public string Code; public string Description; public DateTime ExtendFromDate; public DateTime ExtendToDate; public int Units { get; set; } public string UnitType { get; set; } }}