Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Kendo MVC网格集选择模式的编程方式_Javascript_Jquery_Asp.net Mvc_Kendo Ui_Grid - Fatal编程技术网

Javascript Kendo MVC网格集选择模式的编程方式

Javascript Kendo MVC网格集选择模式的编程方式,javascript,jquery,asp.net-mvc,kendo-ui,grid,Javascript,Jquery,Asp.net Mvc,Kendo Ui,Grid,我有一个剑道MVC网格,我想在选中复选框时使用Javascript或JQuery将SelectionMode从单一模式更改为多模式,在取消选中复选框时从多模式更改为单一模式。这可能吗?我也在绑定和解除绑定变更事件,这与预期的一样有效。这是我目前尝试更改选择模式的方法,但不起作用: <div class="col-md-5 col-sm-5" style="background-color: #52666f;"> <h2 style="color:#f

我有一个剑道MVC网格,我想在选中复选框时使用Javascript或JQuery将SelectionMode从单一模式更改为多模式,在取消选中复选框时从多模式更改为单一模式。这可能吗?我也在绑定和解除绑定变更事件,这与预期的一样有效。这是我目前尝试更改选择模式的方法,但不起作用:

  <div class="col-md-5 col-sm-5" style="background-color: #52666f;">
            <h2 style="color:#fff;font-size:18px;margin-top:10px;margin-left:13px;">MultiSelect Products</h2>
            @(Html.Kendo().CheckBox()
                    .HtmlAttributes(new { style = "" })
            .Name("MultiSelect")
            )
        </div>


    <div class="col-md-12 col-sm-12">
        <h2 style="color:#fff;font-size:18px;margin-top:10px;margin:auto;width:100%;text-align:center;">Select Product</h2>
        @(Html.Kendo().Grid<ManufacturerProduct>()
            .Name("grdMainManufacturerProducts")
            .AutoBind(false)
            .Columns(columns =>
            {
                columns.Bound(manpr => manpr.Name).Width(150);
                columns.Bound(manpr => manpr.GenericStyle).Width(150);
                              })
            .HtmlAttributes(new { style = "height: 420px;" })
            .Selectable(selectable => selectable
                .Mode(GridSelectionMode.Single)
                .Type(GridSelectionType.Row))
            .Scrollable()
            .Sortable()
            .Filterable(filterable => filterable
                        .Extra(false)
                        .Operators(operators => operators
                             .ForString(str => str.Clear()
                             .Contains("Contains")
                                  ))
                            )
            .Pageable(pageable => pageable
                    .Refresh(true)
                    .PageSizes(true)
                    .ButtonCount(5))
            .Events(events => events.Change("onChangeMainManProduct"))
            .Filterable(filterable => filterable
                            .Enabled(true))
            .DataSource(dataSource => dataSource
                .Ajax()
                .Model(model =>
                {
                    model.Id(manpr => manpr.Id); 
                 })
                .Read(read => read
                                      .Url(Url.Content("~/json/ManufacturerProductsController/ManufacturerProduct_ReadMainProduct"))
                              .Data("additionalDataForReadManProducts"))
            )
        )
    </div>

 <script>    
  $(function () {
   $('#MultiSelect').change(function () {
       var checked = $(this).is(':checked');
       onChangeMultiSelect(checked);
   });
});

  function onChangeMultiSelect(checked) {
    var grid = $("#grdMainManufacturerProducts").data("kendoGrid");

    if (checked == true) {
      //alert("Checked!");
        grid.selectable = 'Multiple';
        grid.select.setMode('Multiple');
        ('#grdMainManufacturerProducts).data("kendoGrid").unbind('change');
    }
    else {
      //alert("UnChecked!");
        grid.bind("change", kendoGridWithCheckboxSelectionOnChange);
        grid.selectable = 'Single';
        grid.select.setMode('Single');


    }
}

  function kendoGridWithCheckboxSelectionOnChange() {
    alert("Change reactivated");
  }
</script>
我还制作了一个剑道UI dojo,试图达到预期效果,您可以在这里找到:


有人能解释一下吗?提前谢谢

您可以使用setOptions方法完成此操作,如下所示:

if (checked == true) {
    //alert("Checked!");
    grid.setOptions({
        selectable: "multiple"
    });
    ('#grid').data("kendoGrid").unbind('change');
} else {
    //alert("UnChecked!");
    grid.bind("change", kendoGridWithCheckboxSelectionOnChange);
    grid.setOptions({
        selectable: "single"
    });
}

非常感谢,这是我公认的答案,我已经对你的答案投了票,但由于我还没有足够的声誉,所以它不会显示出来。