剑道网格显示错误"Uncaught TypeError: Cannot read property 'template' of undefined "



未捕获类型错误:无法读取未定义的的属性"template">

我用的是剑道格子。

编辑时要禁用列。(当我添加新记录时不会(。编辑时是否写入代码

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

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

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

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.编辑(不添加(时我想编辑(False(

您可能有太新的jquery版本:http://docs.telerik.com/kendo-ui/getting-started/javascript-dependencies#jquery-版本

当前剑道UI支持jquery 1.9.1。如果您在剑道中使用jquery的更高版本,您可能会遇到closeCell()的问题。

要解决这个问题,你可以使用

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

而不是grid.closeCell()

这取决于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)
    }    
}

相关内容

最新更新