Kendo UI - js grid destroy function not triggered

时间:2015-04-27 13:16:08

标签: javascript jquery kendo-ui

This is my grid:

  $(document).ready(function () {
datasource = new kendo.data.DataSource({
    transport: {
        read: {
            url: '/Discount/Get',
            dataType: "json",
        },
        update: {
            url: '/Discount/Update',
            dataType: "json",
            type: "POST"
        },
        destroy: {
            url: '/Discount/Delete',
            dataType: "json",
            type: "POST"
        },
        create: {
            url: '/Discount/Add',
            dataType: "json",
            type: "POST"
        },
        parameterMap: function (options, operation) {
            console.log(operation);
            if (operation !== "read") {
                return options;
            }
        }
    },
    schema: {
        model: {
            id: "Id",
            fields: {
                TopItemName: { type: "string" },
                DiscountValue: { type: "number" },
            }
        }
    }
});
$("#grid").kendoGrid({
    dataSource: datasource,
    batch: true,
    toolbar: ["create", "save", "cancel"],
    height: 400,
    navigatable: true,
    pageable: true,
    columns: [
    {
        field: "TopItemName",
        editor: topItemDropDown,
        template: "#=TopItemName#"
    },
    {
        field: "DiscountValue",
        format: "{0:p0}",
        editor: function (container, options) {
            $("<input name='DiscountValue'>")
            .appendTo(container)
            .kendoNumericTextBox(
              {
                  min: 0,
                  max: 1.00,
                  step: 0.01
              });
        }
    },
    {
        command: "destroy",
        title: "&nbsp;",
        width: 150
    }],
    editable: true
});

function topItemDropDown(container, options) {
    console.log(options);
    $('<input required data-text-field="TopItemName" data-value-field="TopItemName" data-bind="value:' + options.field + '"/>')
        .appendTo(container)
        .kendoDropDownList({
            autoBind: false,
            dataSource: {
                serverFiltering: true,
                transport: {
                    read: {
                        url: '/Discount/GetTopItemName',
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json"
                    }
                }
            }
        });
    }

});

and somehow when I press the delete button it deletes the row from the grid but it never calls my action method so that the row gets removed from my database. But if I after i have pressed the delete button press add new record and then save changes then it calls my add action method and my delete action method. How can I make it call the delete action method when the delete button is pressed and not when save changes is pressed?

1 个答案:

答案 0 :(得分:0)

这是默认编辑的默认工作方式 - 用户必须点击&#34;保存更改&#34;按钮将所有更改提交到服务器。

您可以执行以下某项操作

  • 将数据源的autoSync选项设置为true
  • 使用其他编辑模式 - 例如inline
  • 处理网格的remove事件并致电this.dataSource.sync()以自动同步更改。