本文介绍了分配新数据源后,Kendo网格批量更新无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的网格。

Following is my grid.

@(Html.Kendo().Grid<VehicleUploadViewModel>()
                        .Name("grid")
                        .Resizable(resize => resize.Columns(true))
                        .Columns(columns =>
                              {
                                  columns.Bound(p => p.ID).Visible(false);
                                  columns.Bound(p => p.RefId).Width(15);
                                  columns.Bound(p => p.IsAcceptReturn).Width(15).ClientTemplate("<input type='checkbox' #= IsAcceptReturn ? 'checked=checked' : '' #></input>");
                                  columns.Bound(p => p.ReturnDuration).Width(15);
                                  columns.Bound(p => p.CurrentSellingMethodId).Width(15);
                                  columns.Bound(p => p.SuggestedOfferPrice).Width(15);
                                  columns.Bound(p => p.Summary).Width(15);
                              })
                                        .ToolBar(toolbar =>
                                    {
                                        toolbar.Save();
                                    })
                                .Pageable(p => p.Refresh(true))
                                .Sortable()
                                .Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode
                                .Scrollable(scrollable => scrollable
                                .Height(366))
                                .Filterable()
                                .Groupable()
                                .Navigatable()
                                .HtmlAttributes(new { style = "width:1138px;" })
                                .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
                                .Reorderable(reorder => reorder.Columns(true))
                                .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Batch(true)
                                    .PageSize(10)
                                    .ServerOperation(false)
                                    .Events(events => events

                                        .Error("error_handler")
                                        .RequestEnd("onRequestEnd"))

                                        .Model(model =>
                                            {
                                                model.Id(p => p.ID);
                                            })
                                            .Read(read => read.Action("UploadRead", "Upload"))
                                            .Update(update => update.Action("Editing_Update", "Upload")))
                                            .Events(e => e.DataBound("onDataBound").Cancel("onCancel"))
                        )





在我的脚本标签中,以下是代码。我在准备好文档时为kendo网格分配一个空白源。





In my script tag, following is the code. I am assigning a blank source to the kendo grid on document ready.

<script>
    var grid;
    $(document).ready(function () {
        grid = $("#grid").data("kendoGrid");
        grid.dataSource.data([]);
    });
    function onUploadSuccess(e) {
    {
        grid.dataSource.data(e.response.Data);
    }
</script>





以下是我的操作结果中的代码,它提供了新的数据源onUploadSuccess函数中的网格。





Following is the code from my action result which gives new data source to grid in onUploadSuccess function.

var request = new DataSourceRequest();
return this.Json(lstUploadVehicles.ToDataSourceResult(request));







Now, the new data is bounded in the grid, I am able to edit the records. But SaveChange is not called.

Here is my save method







[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Editing_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<VehicleUploadViewModel> vehicleUpload)
{
}





为什么我无法调用保存更改方法?



Why I am not able to call save changes method?

推荐答案






以下是我的操作结果中的代码,它提供了新的数据源onUploadSuccess函数中的网格。





Following is the code from my action result which gives new data source to grid in onUploadSuccess function.

var request = new DataSourceRequest();
return this.Json(lstUploadVehicles.ToDataSourceResult(request));







Now, the new data is bounded in the grid, I am able to edit the records. But SaveChange is not called.

Here is my save method







[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Editing_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<VehicleUploadViewModel> vehicleUpload)
{
}





为什么我无法调用保存更改方法?



Why I am not able to call save changes method?


.Model(model =>{model.Id(p => p.ID);})





ID字段存在问题,所有ID都设置为0.

所以需要为您绑定的字段赋予唯一值。



已解决



There was issue with ID field, all the ID were set to 0.
So need to have unique values for the field which you are binding.

Solved


这篇关于分配新数据源后,Kendo网格批量更新无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 12:25