Kendo Grid显示错误“Uncaught TypeError:无法读取未定义的属性'模板'”

时间:2014-04-29 12:42:13

标签: kendo-ui kendo-grid

未捕获的TypeError:无法读取未定义的属性“模板”

我正在使用剑道网格。

我想在编辑时禁用列。(不是在我添加新记录时)。编辑时编写代码

function onEdit(e) {
    var indexCell = 1;
    var grid = $('#consumablesGrid').data('kendoGrid');


    if (e.model.id) { // when Editing the id is defined
        if (indexCell != 'undefined' && grid.columns[indexCell].title == "Consumable") {
            grid.closeCell();    
        }
    }
}

但在执行"Uncaught TypeError: Cannot read property 'template' of undefined "时会显示grid.closeCell()

为了更好地理解,我将包括我的完整网格条件。

function ConsumableManager() {
    $("#consumablesGrid").kendoGrid({
        dataSource: {

            transport: {
                read: {
                    url: "GetConsumablesGrid",
                    type: "POST",
                    contentType: "application/json",
                    dataType: "json"
                },

                update: {
                    url: "UpdateConsumables",
                    contentType: "application/json",
                    type: "POST",
                    dataType: "json",
                    complete: function (data) {
                        var result = jQuery.parseJSON(data.responseText);

                        if (result.State == true) {
                            toastr.success(result.Description);
                            $("#consumablesGrid").data("kendoGrid").dataSource.read();
                        }
                        else {
                            toastr.error(result.Description);
                            $("#consumablesGrid").data("kendoGrid").dataSource.read();
                        }
                    }

                },
                destroy: {
                    url: "DestroyConsumables",
                    contentType: "application/json",
                    type: "POST",
                    dataType: "json",
                    complete: function (data) {
                        var result = jQuery.parseJSON(data.responseText);

                        if (result.State == true) {
                            toastr.success(result.Description);
                            $("#consumablesGrid").data("kendoGrid").dataSource.read();
                        }
                        else {
                            toastr.error(result.Description);
                        }
                    }
                },
                create: {
                    url: "CreateConsumables",
                    contentType: "application/json",
                    type: "POST",
                    dataType: "json",
                    complete: function (data) {
                        var result = jQuery.parseJSON(data.responseText);

                        if (result.State == true) {
                            toastr.success(result.Description);
                            $("#consumablesGrid").data("kendoGrid").dataSource.read();
                        }
                        else {
                            toastr.error(result.Description);
                        }
                    }
                },
                parameterMap: function (data, operation) {
                    if (operation != "read") {
                        return kendo.stringify(data.models);
                    }

                }
            },

            serverPaging: false,
            pageSize: 10,
            batch: true,

            schema: {
                model: {
                    id: "ConsumablesID",
                    fields: {
                        ConsumablesID: { editable: false },
                        Consumable: { editable: true },
                        UnitCost: { editable: true },
                        Currency: { editable: true },
                        ContractID: { editable: false }
                    }
                },
                errors: "Errors"
            },

            error: function (e) {
                alert(e.errors + "grid");
            }
        },
        editable:
            {
                mode: "inline",
                createAt: "bottom"
            },
        pageable: {
            refresh: true,
            pageSizes: true
        },
        toolbar: ["create"],
        sortable: true,
        autoBind: false,

        edit: function (e) {
            alert("Edit");
            onEdit(e);
        },
        update: function (e) {

        },
        columns:
        [

            { field: "ConsumablesID", width: 50, hidden: true, title: "ID" },
            { field: "Consumable", width: 200, title: "Consumable", editor: ConsumablesDropDownEditor },
            { field: "UnitCost", width: 100, title: "Unit Cost" },
            { field: "Currency", width: 200, title: "Currency", editor: CurrencyUnitDropDownEditor },
             { field: "ContractID", width: 85, hidden: true, title: "ContractID" },

            { command: ["edit", "destroy"], title: "Action", width: "175px" }
        ]
    });


    $("#consumablesGrid").data("kendoGrid").dataSource.read();
}

任何人都有想法为什么会这样。我怎么能这样做请回复。

1.我有一个网格

2.编辑时我想要编辑(错误)(不添加)

3 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

当前的Kendo UI支持jquery 1.9.1。如果您将更高版本的jquery与kendo一起使用,则可能会遇到closeCell()的问题。

要修复(解决)此问题,您可以使用

$('#consumablesGrid').getKendoGrid().trigger('cancel')

而不是grid.closeCell()

答案 2 :(得分:0)

这取决于jquery版本。 为避免此问题,您可以使用此脚本

function onEdit(e) {
    if (!e.model.isNew() && (e.model != 'undefined') && (e.model != null)) {
        e.container.find("input[name=GroupName]").hide(); // To hide only the value of the column when updating the row
      //  e.container.find("#GroupName").parent().hide().prev().hide(); //to hide completely the column (value + structure + title name)
    }    
}