添加后,Kendo Grid内联编辑新行消失

时间:2016-03-09 05:07:50

标签: kendo-ui kendo-grid angular-kendo

我有一个带有Angular和远程数据绑定的网格。它的配置是这样的:

    $scope.myGridOptions = {
        dataSource: new kendo.data.DataSource({
                type: "json",
                transport: {
                    create: function(operation) {
                        //calls an Angular service to add
                        DataService.add(operation).success(function(data) {
                            operation.success(data);
                        });
                    },
                    parameterMap: function(options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }
                    }
                },
                pageSize: 10,
                schema: {
                    model: {
                        id: "Id",
                        fields: {
                           ...
                        }
        }),
        toolbar: [ { name: "create", text: "Add New Book" } ],
        autobind: false,
        groupable: false,
        editable: {
            mode: "inline"
        },
        columns: [
            {
                field: "Name",
                title: "Name"
            },
            {
                field: "Description",
                title: "Description"
            },
            {
                command: [
                    { name: "edit", title: "Action" }
                ]
            }
        ]
};

当我点击“添加新书”按钮时,网格中的第一行变成一个空行,并允许我输入数据。完成输入后,我单击“更新”以保存数据,第一行变为常规的只读行,并验证新行已添加到远程数据库。到现在为止还挺好。但是,当我点击新行上的“编辑”按钮,然后单击“取消”按钮时,我的新行将消失,直到我刷新页面。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

为了让kendo dataSource在保存后同步数据,您需要将新创建的行从服务器返回到dataSource。这也适用于更新。