我想保存' true'并且' false'当选中或不选中Checkbox时。这个复选框我在kendo网格的一列中。但是我无法做到。我的代码如下:
@(Html.Kendo().Grid<Invoice.Models.ViewModels.Cashbox.HeaderkViewModel>()
.Name("transactionGrid")
.Columns(columns =>
{
columns.Bound(p => p.IsAllocatable).HeaderHtmlAttributes(new { title = "Total Amount" }).Title("Total").ClientTemplate("<input type='checkbox' value='#=data.IsAllocatable#' class='IsAllocatable' onclick='Allocatable(this)' />").Width(30);
})
.ToolBar(toolbar =>
{
//toolbar.Template("<a class='k-button k-button-icontext' onclick='customCommand()' href='#'></span>Cutom Command</a>");
toolbar.Create();
//toolbar.Save();
})
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:280px;" })
.Navigatable()
.Editable(ed => ed.Mode(GridEditMode.InCell)) //Having Different Template for New Dossier
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.Model(model =>
{
model.Id(p => p.HeaderID);
})
.Create(create => create.Action("Dossier_Create", "Dossier", new { @CompanyID = ViewBag.CompanyID }))
.Update(create => create.Action("Dossier_Create", "Dossier", new { @CompanyID = ViewBag.CompanyID }))
.Destroy(create => create.Action("Dossier_Create", "Dossier", new { @CompanyID = ViewBag.CompanyID }))
)
.Resizable(resize => resize.Columns(true))
)
<script type="text/javascript">
function Allocatable(element) {
if (element.checked) {
element.value = 'true';
var firstItem = $('#transactionGrid').data().kendoGrid.dataSource.data()[0];
firstItem.set('IsAllocatable', true);
if (element.value == true) { $(element).checked; }
}
}
</script>
试着帮我解决这个问题
答案 0 :(得分:0)
我认为当您设置复选框的值时,您遇到了问题。想想而不是说data.IsAllocatable你应该写IsAllocatable,所以像这样:
.ClientTemplate("<input type='checkbox' value='#=IsAllocatable#'class='IsAllocatable'
onclick='Allocatable(this)' />").Width(30);