1

下面是我的网格。

如果您查看该save:事件,您会注意到一个 AJAX 调用。

这个 AJAX 调用正在触发,数据正在插入到数据库中,我什至可以看到警报功能正在运行。但是,网格不会退出我正在内联编辑的行的编辑模式。我不确定发生了什么,因为错误消息很糟糕。我不断得到:

TypeError: Cannot read property 'data' of undefined [http://localhost/x/Scripts/kendo.web.min.js:13]

这是网格:

function directorsOrRecipients(e)
{
    awardTitleId = e.data.AwardTitleId;

    var detailRow = e.detailRow;

    detailRow.find(".childTabstrip").kendoTabStrip({
        animation: {
            open: { effects: "fadeIn" }
        }
    });

    detailRow.find(".directorsOrRecipients").kendoGrid({
        reorderable: true,
        resizable: true,
        dataSource: {
            transport: {
                read: {
                    url: "http://localhost/x/api/Awards/directors/" + awardTitleId,
                    type: "GET"
                },
            },
            schema: {
                model: {
                    id: "AwardDirectorId",
                    fields: {
                        "AwardDirectorId": { editable: false, type: "number" },
                        "namefirstlast": { editable: true, type: "string" },
                        "directorsequence": { editable: true, type: "number", validation: { min: 1 } },
                        "isonballot": { editable: true, type: "string" },
                        "concatenation": { editable: true, type: "string" },
                        "MoreNames": { editable: true, type: "number", validation: { min: 0 } },
                    }
                }
            }
        },
        columns: [
            { field: "AwardDirectorId", title: "Award Director Id" },
            { field: "namefirstlast", title: "Name", editor: namesAutoComplete },
            { field: "directorsequence", title: "Director Sequence", format: "{0:n0}" },
            { field: "isonballot", title: "On ballot?", editor: onBallotDropDownEditor },
            { field: "concatenation", title: "Concatenation" },
            { field: "MoreNames", title: "More names?", format: "{0:n0}" },
            { command: ["edit"], title: " ", width: 100 }],
        sortable: true,
        sort: { field: "namefirstlast", dir: "desc" },
        editable: "inline",
        toolbar: [{ name: "create", text: "Add New Director/Recipient" }],
        save: function(e)
        {
            debugger;

            if (e.data != "undefined")
            {

                $.ajax({
                    url: "http://localhost/x/api/awards/directors",
                    type: "POST",
                    dataType: "json",
                    data: $.parseJSON(directorData)
                }).done(function()
                {
                    alert('done!');
                });
            }

        }
    });

    function onBallotDropDownEditor(container, options)
    {
        var data = [
            { "onBallotId": 1, "onBallotDescription": "Yes" },
            { "onBallotId": 2, "onBallotDescription": "No" }];

        $('<input required data-text-field="onBallotDescription" data-value-field="onBallotDescription" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                autoBind: false,
                dataSource: data
            });
    }
}
4

2 回答 2

2

在 Ajax 调用成功后试试这个,

$('#GridName').data('kendoGrid').dataSource.read();
$('#GridName').data('kendoGrid').refresh();
于 2013-09-07T08:52:02.773 回答
0

在控制器更新函数中返回一个空 Json 的对象,就像这样它对我有用

return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());
于 2016-10-12T20:15:32.293 回答