简体   繁体   English

内联编辑/创建asp.net mvc的[kendo ui]后,如何刷新网格的所有行

[英]How to refresh all rows of grid after inline editing/creating [kendo ui] for asp.net mvc

I have nested grids. 我有嵌套的网格。 Inner grid allows inline editing. 内部网格允许内联编辑。 In special cases after creating new element (row in table) in inner grid, other row of inner grid should be changed. 在特殊情况下,在内部网格中创建新元素(表中的行)后,应更改内部网格的另一行。 I change that row in database but I dont know how to refresh inner grid. 我更改数据库中的该行,但不知道如何刷新内部网格。 If user press "refresh button" of the grid the data will be shown. 如果用户按下网格的“刷新按钮”,则将显示数据。 How to make inner grid refreshing after adding/editing elements? 添加/编辑元素后如何使内部网格刷新?


Outer grid 外网

@(Html.Kendo().Grid<Portal2.Areas.ResourceGrouping.Models.TruckTrailerDriverViewModel>()
  .Name("TruckGrid")
  .DataSource(dataSource => dataSource
      .Ajax()
      .Events(events => events.Error("error_handler"))
      .Model(model => model.Id(m => m.Id))
        .Read(read => read.Action("JsonTruckTrailerDriverRead", "TrucksGrouping"))
   )
  .Columns(columns =>
  {
      columns.Bound(x => x.TruckRegNum);
      columns.Bound(x => x.TrailerStartDate);
      columns.Bound(x => x.TrailerEndDate);
      columns.Bound(x => x.TrailerRegNum);
      columns.Bound(x => x.DriverStartDate);
      columns.Bound(x => x.DriverEndDate);
      columns.Bound(x => x.DriverName);
  })
  .Pageable(p => p
      .Refresh(true)
      .PageSizes(true)
      .ButtonCount(5)
      .PageSizes(new[] { 20, 30, 40, 50, 100 }))
  .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
  .Reorderable(reorder => reorder.Columns(true))
  .Events(events => events
      .DetailExpand("detailExpand")
      )
  .ClientDetailTemplateId("template")
)

Template 模板

<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().TabStrip()
      .Name("tabStrip_#=Id#")
      .SelectedIndex(0)
      .Animation(animation => animation.Open(open => open.Expand(ExpandDirection.Vertical)))
      .Items(items =>
      {
          items.Add().Text("Прицепы").Content(@<text> @TruckTrailer() </text>);
          items.Add().Text("Экипажи").Content(@<text> @TruckDriver() </text>);
      })
                        .ToClientTemplate()
)

Inner grid 内网

    @helper  TruckTrailer()
{
    @(Html.Kendo().Grid<Portal2.Areas.ResourceGrouping.Models.CouplerViewModel>()
            .Name("grid_trailers_#=Id#")
            .Columns(columns =>
            {
                columns.Bound(col => col.TruckRegNum);
                columns.Bound(col => col.TrailerRegNum).EditorTemplateName("TrailerTemplateEditor").Width(100);
                columns.Bound(col => col.StartDate).EditorTemplateName("DateTimeEditor").Width(200);
                columns.Bound(col => col.EndDate).EditorTemplateName("DateTimeEditor").Width(200);
                columns.Command(c => c.Edit());
                columns.Command(c => c.Destroy());

            })
            .Sortable()
            .Editable(editable => editable.Mode(GridEditMode.InLine))
            .ToolBar(toolbar => { toolbar.Create(); })
            .DataSource(data => data
                .Ajax()
                .Sort(sort => sort.Add("StartDate").Descending())
                .Events(events =>
                {
                    events.Error("error_handler");
                })
                .Model(model =>
                {
                    model.Id(m => m.Id);
                })
                //required: назвать поле именем, отличным от TruckId (например OwnerTruckId), иначе кендо отказываетсая работать
                .Create(update => update.Action("JsonCouplerCreate", "TrucksGrouping", new { OwnerTruckId = "#= Id #" }))
                .Read(read => read.Action("JsonCouplerRead", "TrucksGrouping", new { TruckId = "#= Id #" }))
                .Update(update => update.Action("JsonCouplerUpdate", "TrucksGrouping"))
                .Destroy(update => update.Action("JsonCouplerDestroy", "TrucksGrouping"))
            )
            .Pageable(pager => pager.Refresh(true))
            .Filterable(ftb => ftb.Mode(GridFilterMode.Menu))
            .Reorderable(reorder => reorder.Columns(true))
            .ToClientTemplate()
    )
}

Controller 调节器

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult JsonCouplerCreate([DataSourceRequest]DataSourceRequest request, CouplerNewViewModel model)
    {
        Guid newItemId = Guid.Empty;
        if (model != null && ModelState.IsValid)
        {
            newItemId = TrucksGroupingUtility.Create(model, User.Identity.Name);

            var jsonContactsCreate = Json(GetSingleCouplerViewModel(newItemId).ToDataSourceResult(request, ModelState));
            return jsonContactsCreate;
        }

        return Json(new[] { model }.ToDataSourceResult(request, ModelState));

    }

If i missed some nessesary code to understand my problem pls write here in comments - i will add 如果我错过了一些必要的代码来了解我的问题,请在此处写上注释-我将添加

Solution: add event listener to datasource of inner grid 解决方案:将事件侦听器添加到内部网格的数据源

.Events(events => events.Error("error_handler").Sync("sync_handler"))



 function sync_handler(e) {
   this.read();
}

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

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