0

当勾选复选框时,我如何防止用户一次只检查一条记录。目前用户可以勾选多条记录。请指教,谢谢

@(Html.Kendo().Grid<TRC.Models.ProductModel>()
    .Name("Product")
    .HtmlAttributes(new { @Style = "align:center; font-size:12px; width:470px; height:100%" })
    .Columns(columns =>
    {

          columns.Template(p => p.Id).ClientTemplate("<input type='checkbox' class='chkbx'/> ").Width(25);
        columns.Bound(p => p.ProductId).Width(220);
        columns.Bound(p => p.ProductName).Width(220);
        columns.Bound(p => p.ProductCreateDate).EditorTemplateName("Date").Format("{0:dd/MM/yyyy}").Width(120);
        //columns.Command(commands => commands.Edit()).Width(100);
        columns.Command(commands => commands.Destroy());
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Sortable()
    .Selectable()
    .Scrollable(scrollable => scrollable.Virtual(true))
    .ColumnMenu(c => c.Columns(false))
    .DataSource(dataSource => dataSource
        .Ajax()//bind with Ajax instead server bind
        .ServerOperation(true)
            .Model(model =>
            {
                model.Id(p => p.ProductId);
                model.Field(p => p.ProductCreateDate).DefaultValue(DateTime.Now);
                model.Field(p => p.ProductCreateDate).Editable(false);

            })
            .Sort(sort => sort
            .Add(x => x.ProductCreateDate).Descending()
        )
        .Read(read => read.Action("GetProduct", "ProductDetails").Type(HttpVerbs.Get))
        .Destroy("DeleteProduct", "ProductDetails")
    )
)
4

1 回答 1

0

假设您有以下处理点击的逻辑。然后您可以像这样将其他模型字段设置为 false:

$('#grid').on('click', '.chkbx', function () {
    var checked = $(this).is(':checked');


    var grid = $('#grid').data().kendoGrid;
    //clearAll all other checked
    if(checked){
       $.each(grid.dataSource.view(),function(){
           this.isAdmin = false;
       })
    }

    var dataItem = grid.dataItem($(this).closest('tr'));
    dataItem.set('IsAdmin', checked);
})
于 2013-11-13T19:18:40.967 回答