【问题标题】:Kendo grid update - update click of any row shows 1st row details剑道网格更新 - 任何行的更新单击显示第一行详细信息
【发布时间】:2014-05-29 16:32:56
【问题描述】:

我遇到了剑道网格内联编辑的问题,即使我更新了任何行,第一行数据也显示在网格中,对此有何帮助?

更新前

更新后。

有趣的是,我从控制器返回的对象确实有正确的数据

控制器代码

    [AcceptVerbs(HttpVerbs.Post)]
    [ValidateAntiForgeryToken]
    [ActionSessionState(System.Web.SessionState.SessionStateBehavior.Required)]
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public ActionResult _SaveBatchEditingintegrate([DataSourceRequest] DataSourceRequest request)
    {
        var UPObj = SessionFacade.UserProfile as UserProfile;

        try
        {
            IntegrationRate objInteg = new IntegrationRate();
            TryUpdateModel(objInteg);
            if (objInteg.PeriodID != 0)
            {
                var Integrationrate = (from p in _draftManagecompany.IntegrationRates where p.PeriodID == objInteg.PeriodID select p).First();
                TryUpdateModel(Integrationrate);
                if (Integrationrate.Rate > 100) //set 100 as default
                {
                    Integrationrate.Rate = 100;
                }
            }
            LoadResourceJSArray();
        }
        catch (Exception ex)
        {
            // Adding related additional information along with exception object
            //ExceptionLogger.Log(ex, "Period ID", id);
            ExceptionLogger.Log(ex, "User Profile Info", UPObj);

            // Handle exception with BubbleExceptionPolicy
            if (exManager.HandleException(ex, "BubbleExceptionPolicy"))
                throw;  // Not to include the ex, as the previous stack trace to be maintained
        }
//_draftManagecompany.IntegrationRates contains updated value in the correct order
        return Json(_draftManagecompany.IntegrationRates.ToDataSourceResult(request));


    }

cshtml代码:

 @{ var integrateGrid = Html.Kendo()
            .Grid(Model.Company.IntegrationRates)
            .Name("Gridintegrate")
            .EnableCustomBinding(true) // Enable custom binding
            .BindTo(Model.Company.IntegrationRates)
            .Events(events =>
            {
                events.Change("DataBound_Integ");

            })
            .ToolBar(
                commands =>
                {
                    //commands.Insert().ButtonType(GridButtonType.BareImage).ImageHtmlAttributes(new { style = "visibility:hidden" });
                }
            )
            .Columns(columns =>
            {

                columns.Bound(p => p.PeriodID).Visible(false);
                columns.Bound(p => p.Month).Width(150);
                columns.Bound(p => p.Rate).Format("{0:0.00}%").Width(100);

                columns.Command(commands =>
                {
                    commands.Edit().HtmlAttributes(new { @id = "btn_IntRateEdit" });

                }).Width(150).Title(gridTitle);
            })
            .HtmlAttributes(new { style = "height: 380px;" })
            .Scrollable()
            .Editable(editable => editable.Mode(GridEditMode.InLine))
            .DataSource(dataSource => dataSource.Ajax()
                //.Batch(true) 
                .Read(read => read.Action("_AjaxBindingintegrate", "Company"))
                .Update(update => update.Action("_SaveBatchEditingintegrate", "Company"))

                .Model(model =>
                    {
                        model.Id(c => c.PeriodID);
                        model.Field(c => c.Month).Editable(false);
                    }

                )
                 .Events(events =>
                 {
                     events.Error("CheckSessionExistsOnTelerik");


                 })

            );
        //.Pageable(paging => paging.Style(GridPagerStyles.NextPreviousAndNumeric | GridPagerStyles.PageSizeDropDown).PageSize(20, new int[3] { 20, 50, 100 })).ToComponent();

        var culture = System.Globalization.CultureInfo.InvariantCulture;
        //integrateGrid.Localization = new GridControlLocalization(culture);
        integrateGrid.Render();


                    }

【问题讨论】:

  • 这通常发生在服务器为编辑的记录返回null id 时。您是否在更新时发回记录并正确返回id
  • 我没有看到任何空值,事实上如果我保存这些更改并重新加载网格,更新的值会被反映,但在点击更新后,每行更新立即被第一行数据覆盖
  • 有没有办法在点击更新后显式刷新网格?如果是这样,在哪种情况下我需要编写刷新代码?,如果我能做到这一点,它可以解决这个问题。
  • 您不必这样做。您的更新方法应在更新后返回记录。 KendoUI 将完成剩下的工作。如果您不将其发回,则该记录将被删除

标签: kendo-ui kendo-grid kendo-asp.net-mvc inline-editing


【解决方案1】:

我想我在这里看到了问题。据我所知,当您完成更新时,您将在更新时返回整个数据集,即 6 月、1 月、2 月等。

在更新时,您只需将已更新的项目返回到网格中

因此,在您的示例中,将返回 json 更改为以下内容:

Return json(new { IntegrationRate}.toDataSourceResult(request,modelState),jsonbehaviour.allowget);

这应该可以解决您的问题。

因为您要返回整个数据集,所以它会将第一行呈现为预期结果。

正如您所说,您在幕后看到了正确保存的数据。所以你知道没有抛出错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-25
    • 2016-11-24
    • 2014-09-08
    相关资源
    最近更新 更多