当填充datasource._destroyed时,Kendo UI sync()不会触发(脏)

时间:2014-10-02 22:45:08

标签: javascript kendo-ui kendo-grid kendo-datasource

以下是代码的精简版本:

gridDataSource = new kendo.data.DataSource({
        batch: true,
        transport: {
            read: {
                url: 'Equipment'
            },
            destroy: {
                url: 'Equipment',
                contentType: "application/json",
                dataType: 'json',
                type: "DELETE"
            },
            parameterMap: function (options, operation) {
                if (operation == "read") {
                    return "this=works-fine";
                } else {
                    alert('not reading');
                    return kendo.stringify(options.models);
                }
            }
        },
        schema: {
            id: "EquipmentId",
            fields: {
                Value: { type: "number" }
            }
        }
    });

kendoGrid = gridObj.kendoGrid({
        dataSource: gridDataSource,
        selectable: 'row',
        navigatable: true,
        change: rowSelect,
        sortable: true,
        pageable: false,
        columns: [
            { field: "Value" },
        ]
    }).data('kendoGrid');

读取工作正常,我删除了一行(或多行)(selectedRow正确填充,只是为了简洁而跳过):

    $('#footer-remove').off().on('click', function () {
        kendoGrid.removeRow('table tr[data-uid="' + selectedRow.uid + '"]');
        console.log(gridDataSource._destroyed);
    });

它显示在gridDataSource._destroyed中,我的所有测试都显示gridDataSource是脏的。

当我调用同步时,如果我只是删除则没有任何反应。我错过了什么?谢谢。

1 个答案:

答案 0 :(得分:1)

您需要在editable的初始化中将true设置为grid

kendoGrid = gridObj.kendoGrid({
    dataSource: gridDataSource,
    selectable: 'row',
    navigatable: true,
    change: rowSelect,
    sortable: true,
    pageable: false,
    editable: true,
    columns: [
        { field: "Value" },
    ]
}).data('kendoGrid');

如果您不希望单元格可更新(只是被删除),那么您应该设置editable如下:

editable: {
    destroy: true,
    update: false
},

此外,将editable.confirmation设置为false会在删除时禁用弹出提示进行确认。

编辑

destroy未执行的原因是Datasource定义中存在错误,schema应包含model元素然后定义(您错过了) model)。

schema: {
    model: {
        id: "EquipmentId",
        fields: {
            Value: { type: "number" }
        }
    }
}

您可以在此处看到它:http://jsfiddle.net/OnaBai/dq6jh3yp/4/