kendo grid delete命令无法正常工作

san*_*nzy 15 kendo-ui kendo-grid

我使用kendo ui工具开发了一个Web应用程序,还有一个带有批量编辑模式的kendo网格.

但是当我按下删除按钮以获取剑道网格中的任何记录时,它将从网格中的列表中删除但实际上不在数据源中.当我重新加载页面或网格时,删除的项目仍然存在.

这是我网格的代码

<div id="grid">
        </div>
        <script type="text/javascript">

            $("#submitMarketUser").click(function () {
                var grid = $("#grid").data("kendoGrid");
                var dataSource = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: "WholeSaleTrade/GetTradeProductDetail",
                            dataType: "json",
                            data: {
                                test: $("#Names").val()
                            }
                        },
                        destroy: {
                            url: "WholeSaleTrade/DeletePro",
                            type: "POST",
                            dataType: "jsonp",
                            data: {
                                DAKy: $("#Names").val(),
                                DIKy: $("#btntxt").val()
                            }
                        },
                        create: {
                            url: "WholeSaleTrade/CreateProduct",
                            type: "POST",
                            dataType: "jsonp",
                            data: {
                                AKy: $("#Names").val(),
                                IKy: $("#btntxt").val()
                            }
                        }
                    },
                    pageSize: 5,
                    schema: {
                        model: {
                            id: "ProductKey",
                            fields: {
                                ProductKey: { editable: false, nullable: true },
                                ProductName: { validation: { required: true} }
                            }
                        }
                    }
                });
                $("#grid").kendoGrid({
                    dataSource: dataSource,
                    editable: true,
                    toolbar: ["create", "save"],
                    autobind: true,
                    pageable: true,
                    columns: [
                        { field: "ProductName", title: "Product Name",
                            editor: function (container, options) {
                                var model = options.model;
                                $('<input id="btntxt" name="' + options.field + '"/>').appendTo(container).kendoComboBox({
                                    dataSource: {
                                        type: "POST",
                                        transport: {
                                            read: {
                                                url: "MarketInformation/PopulateProducts",
                                                success: function (data) {
                                                    var prod = data[0];
                                                    model.set("ProductName", prod.ItmNm);
                                                    model.set("ItmKy", prod.ItmKy);
                                                    model.set("UserKey", $("#Names").val());
                                                }
                                            }
                                        }
                                    },

                                    dataValueField: "ItmKy",
                                    dataTextField: "ItmNm"
                                });
                            }
                        },
                        { command: ["destroy"], title: "&nbsp;" }
                    ]
                });
            });

        </script>
Run Code Online (Sandbox Code Playgroud)

无法确定故障在哪里,有人可以帮我解决这个问题.

Ima*_*sab 37

删除不起作用有三个常见原因:


1.未设置editable网格inlinepopup.删除的项目将通过传输销毁自动处理仅针对"内联"/"弹出"编辑模式.例如:

editable: {
   mode: "inline",
}
//or
editable: "inline"
Run Code Online (Sandbox Code Playgroud)


2.如果在您的数据源上,您将batch标志设置为true,这意味着数据源将在您告知之后进行调用,例如调用sync().例如:

var dataSource = new kendo.data.DataSource({
    batch: true,
    //.....
});
//... in some where e.g in a save button click event call the following line:
dataSource.sync();
Run Code Online (Sandbox Code Playgroud)


3.您应该定义id里面你的数据库字段名的主键model数据源.例如:

   model: {
        id: "ProductID",
        fields: {
            ProductID: { editable: false, nullable: true },
        }
    }
Run Code Online (Sandbox Code Playgroud)


所以你的代码问题首先是一个,即你没有设置editableinlinepopup