简体   繁体   English

Kendo UI网格弹出窗口在AJAX数据后不起作用

[英]Kendo UI grid popup not working after AJAX data

I have a kendo grid which has data populated via AJAX. 我有一个剑道网格,其中包含通过AJAX填充的数据。

If I take out the AJAX all is fine but when I populate the data via AJAX the edit button doesn't bring up the pop up. 如果我取出AJAX,一切都很好,但是当我通过AJAX填充数据时,编辑按钮不会弹出该弹出窗口。

The grid itself looks like this: 网格本身看起来像这样:

<div id="DefinedLevelsGridContainer">
@(Html.Kendo().Grid(Model.Where(x => x.OrgLevel == 0).First().DefinedFieldsList)
    .Name("DefinedlevelsGrid")
    .Columns(columns =>
    {
        columns.Bound(x => x.FieldName).Title("Name");
        columns.Bound(x => x.FieldTypeText).Title("Type");
        columns.Bound(x => x.isMandatory).Title("Mandatory");
        columns.Bound(x => x.DefaultValue).Title("Default Value");
        columns.Bound(x => x.UpdatedOn).Title("Updated");
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("_OrgDefinedFieldEdit"))
    .Pageable()
    .Sortable()
    .DataSource(dataSource => dataSource
    .Server()
    .Model(model => model.Id(x => x.FieldId))
    .Update(update => update.Action("Update", "Home"))
    .Destroy(destroy => destroy.Action("Destroy", "Home"))
    )
)

As you can see I am populating it, by default, with the first item in a list of data. 如您所见,默认情况下,我使用数据列表中的第一项填充它。

I then have this: 然后我有这个:

$(window).load(function () {
    $(".LevelSelector:first").click();
});

Which calls the following function: 其中调用以下函数:

$(".LevelSelector").click(function () {
        var rootString = $(this).html();
        var splitString = rootString.split("-");
        var levelGuid = $(this).attr("LevelGuid").toString();

        $("#LevelEditName").text($.trim(splitString[0]));
        $("#LevelEditInput").val($.trim(splitString[1]));
        $("#CreatedOn").text($(this).attr("CreatedDate"))
        $("#CreatedBy").text($(this).attr("CreatedBy"))
        $("#UpdatedOn").text($(this).attr("UpdatedDate"))
        $("#SelectedLevelGuid").text(levelGuid)

        var Url = '@Url.Action("GetLevelFields", "OrganisationAJAX")' + '?LevelGuid=' + levelGuid;

        $.ajax({
            url: Url,
            contentType: "application/json; charset=utf-8",
            type: 'POST',
            context: this,
            timeout: 60000,
            dataType: 'json',
            tryCount: 0,
            retryLimit: 3,
            success: function (data) {

                var grid = $("#DefinedlevelsGrid").data("kendoGrid");
                grid.dataSource.data(data);
            },
            error: function (httpRequest, textStatus, errorThrown) {
                $(".Message").text("Error: " + textStatus + " " + errorThrown);
            }
        });
    });

The first part is populating another part of the page and then it does an AJAX call to go and get the data. 第一部分填充页面的另一部分,然后执行AJAX调用以获取数据。 On success it populates the grid. 成功后,它将填充网格。

That all works. 一切正常。

But when I click on edit it doesn't load the grid. 但是,当我单击“编辑”时,它不会加载网格。 It does move to the top of the page so I know it is firing. 它确实移到页面顶部,所以我知道它正在触发。

If I stop the pre population by AJAX it does load up the template so I know the template isn't at fault. 如果我通过AJAX停止预填充,则确实会加载模板,因此我知道模板没有问题。

In vcase anyone else sees this, I fixed it by changing .Server to .Ajax. 在vcase中,其他人都看到了这一点,我通过将.Server更改为.Ajax来解决了这个问题。

So it would look like this: 所以它看起来像这样:

@(Html.Kendo().Grid(Model.Where(x => x.OrgLevel == 0).First().DefinedFieldsList)
.Name("DefinedlevelsGrid")
.Columns(columns =>
{
    columns.Bound(x => x.FieldName).Title("Name");
    columns.Bound(x => x.FieldTypeText).Title("Type");
    columns.Bound(x => x.isMandatory).Title("Mandatory");
    columns.Bound(x => x.DefaultValue).Title("Default Value");
    columns.Bound(x => x.UpdatedOn).Title("Updated");
    columns.Command(command => { command.Edit(); command.Destroy(); });
})
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("_OrgDefinedFieldEdit"))
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax() //<------- Changed to .Ajax()
.Model(model => model.Id(x => x.FieldId))
.Update(update => update.Action("Update", "Home"))
.Destroy(destroy => destroy.Action("Destroy", "Home"))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM