1

我有嵌套網格創建[劍道UI。內部網格允許內聯編輯。在內部網格中創建新元素(表中的行)後的特殊情況下,應更改內部網格的其他行。我在數據庫中更改該行,但我不知道如何刷新內部網格。如果用戶按網格的「刷新按鈕」,數據將被顯示。添加/編輯元素後如何使內部網格刷新?如何刷新網格的所有行內聯編輯後/對asp.net的MVC


外網格

@(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") 
) 

模板

<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() 
) 

內網​​格

@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() 
    ) 
} 

控制器

[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)); 

    } 

如果我錯過了一些所必要的代碼來理解我的問題,請在評論中寫到這裏 - 我會添加

+0

必須將事件聽衆對'Save'內網格,然後,在你相應的JavaScript函數,刷新電網 – chiapa

+0

基亞帕,我不知道爲什麼,但是當我擴大外網的詳細信息內網的每個事件的事件監聽器被解僱。 (我檢查了警報) – thedoctorde

回答

1

解決方案:事件監聽器添加到內網的數據源

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



function sync_handler(e) { 
    this.read(); 
} 
相關問題