【问题标题】:Kendo UI - js grid destroy function not triggeredKendo UI - 未触发js网格破坏功能
【发布时间】:2015-04-27 13:16:07
【问题描述】:

这是我的网格:

  $(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"
                    }
                }
            }
        });
    }

});

不知何故,当我按下删除按钮时,它会从网格中删除该行,但它从不调用我的操作方法,以便将该行从我的数据库中删除。但是,如果我在按下删除按钮后按下添加新记录然后保存更改,那么它会调用我的添加操作方法和我的删除操作方法。如何让它在按下删除按钮而不是按下保存更改时调用删除操作方法?

【问题讨论】:

    标签: javascript jquery kendo-ui


    【解决方案1】:

    这是默认编辑的默认工作方式 - 用户必须单击“保存更改”按钮才能将所有更改提交到服务器。

    您可以执行以下操作之一

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

    【讨论】:

      猜你喜欢
      • 2012-12-29
      • 2011-06-23
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多