首页 > 解决方案 > Kendo UI JQuery - 网格一键触发多个“读取”、“创建”、“更新”和“销毁”操作

问题描述

  1. 当我使用“kendo.data.GanttDataSource”时,网格会从控制器触发所有“读取”、“创建”、“更新”和“销毁”操作方法:但当我使用“kendo.data.DataSource”时,只有网格触发“读取”。
  2. 当我点击“添加新记录”按钮时,会触发一个相应的创建操作方法(成功)但也会触发多个失败的更新操作方法(这些触发的数量等于网格中的行数。内部服务器错误( 500)为每个调用返回)
  3. 当我点击删除时,会为所有记录触发删除操作方法,从而使我的网格为空。

<script>
    $(document).ready(function () {
        var datasource = new kendo.data.GanttDataSource({
            type: "json",
            transport: {
                read: {
                    url: '@Url.Action("Details", "Student")',
                    //url: "/Student/Details",
                    dataType: "json",
                    type: "GET"
                },
                create: {
                    url: '@Url.Action("AddStudent", "Student")',
                    //url: "/Student/AddStudent",
                    dataType: "json",
                    type: "POST"
                },
                update: {
                    url: '@Url.Action("UpdateStudent", "Student")',
                    //url: "/Student/UpdateStudent",
                    dataType: "json",
                    type: "POST"
                },
                destroy: {
                    //url: '@Url.Action("DeleteStudent", "Student")',
                    url: "/Student/DeleteStudent",
                    dataType: "json",
                    type: "POST"
                },
                parametermap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                },
                pageSize: 2,
                schema: {
                    model: {
                        id: "rollno",
                        fields: {
                            rollno: { from: "rollno", type: "number" },
                            name: { from: "name", type: "string" },
                            address: { from: "address", type: "string" }
                        }
                    }
                }
            }
        });

$("#stdGrid").kendoGrid({
            dataSource: datasource,
            columns: [
                {
                    field: "rollno",
                    title: "Roll No."
                },
                {
                    field: "name",
                    title: "Name"
                },
                {
                    field: "address",
                    title: "Address"
                },
                { command: [ "edit", "destroy"], titlt:"&nbsp"}
            ],
            toolbar: ["search", "create"],
            //autobind: true,
            autosync: false,
            filterable: true,
            sortable: true,
            editable: "inline",
            pageable: true,
            save: function (e) {
                setTimeout(function () {
                    //$("#stdGrid").data("kendoGrid").refresh();
                    $("#stdGrid").data("kendoGrid").dataSource.read();
                }, 200);
            }
        });
    });
</script>

<style type="text/css">
    .k-grid-search {
        margin-left: auto;
        margin-right: 0;
    }
</style>

标签: kendo-gridkendo-datasource

解决方案


推荐阅读