Kendo Grid BeforeEdit事件不存在

时间:2017-10-12 00:15:24

标签: jquery asp.net-mvc telerik kendo-grid

文档清楚地显示了Grid上的BeforeEdit事件:

然而,没有提到它的版本。我们使用的是版本2016.3.914。我得到一个错误,说它不存在(我尝试在MVC代码和jquery中使用)。

function onDataBound(gridName) {
    return function (e) {
        var grid = $("#" + gridName).data("kendoGrid");
        species = extractSpecies(gridName);
        $("#Species").val(species);
        $("#" + gridName).data("kendoGrid").beforeEdit((e2) => {
            console.log("before edit");
        });
        console.log('WATCH01 NoiNLSConsignment / onDataBinding() - species is: ', species);
    }
}
OpenNlsApplication?exporterId=6190&applicationId=6191:2457 

Uncaught TypeError: $(...).data(...).beforeEdit is not a function(…)
    (anonymous function)    @ OpenNlsApplication?exporterId=6190&applicationId=6191:2457
    trigger                 @ kendo.all.min.js:25
    refresh                 @ kendo.all.min.js:51
    d                       @ jquery.min.js:2
    trigger                 @ kendo.all.min.js:25
    _process                @ kendo.all.min.js:28
    success                 @ kendo.all.min.js:27
    success                 @ kendo.all.min.js:27
    n.success               @ kendo.all.min.js:27
    i                       @ jquery.min.js:2
    fireWith                @ jquery.min.js:2
    y                       @ jquery.min.js:4
    c                       @ jquery.min.js:4

第一个问题是你如何判断Kendo中添加了哪些功能?

其次,我无法控制使用的版本。有没有一种方法可以在编辑发生之前进入生命周期?即。 event.Edit()为时已晚。

1 个答案:

答案 0 :(得分:0)

我对第二个问题有答案*。

我发现在editing时(而不是在creating时)我只需要'BeforeEdit',因此很容易在编辑按钮中添加一些jquery:

function onDataBound(gridName) {
    return function (e) {
        // This part is for when create a new Species / Animal Type
        species = extractSpecies(gridName);
        $("#Species").val(species);

        // This next part is for when edit
        // It would have been preferable to use the beforeEdit event, however that doesn't seem to exist in the version of
        // MVC Kendo that is being used currently (2016.3.914)
        $("div#" + gridName + " a[title*='edit this Animal']").on('click', function () {
            var localSpecies = extractSpecies(gridName);
            $("#Species").val(localSpecies);
            species = localSpecies; // Set the global
        });
    }
}

在Grid的定义中:

 <%  
   Html.Kendo().Grid<NoiNlsConsignmentVO>()
                    .Name(gridNameID)
                    ...
                    .Events(events => {
                        events.Edit("onEditLivestockClicked(\"" + gridNameID + "\")");
                        events.DataBound("onDataBound(\"" + gridNameID + "\")");
                        events.Save("onLivestockSave(\"" + gridNameID + "\")");
                    })
                    .Sortable()
                    .Render();
%>

*我会将此添加为评论,因为这不是一个完整的答案,但是您无法在评论中添加代码(或换行符)