2013-12-23 63 views
1

我在mvc 4中創建了一個kendo層次結構網格。在執行網格時,層次結構網格會自動擴展到第一行,但是當我展開另一行時,新層次結構網格出現空白,而較早層次結構網格(默認出現)的數據已更改。層次結構Kendo Grid在Mvc中無法正常工作4

1.我如何才能讓它顯示 特定行的層次結構網格中的數據,而不僅僅是默認打開的網格中?

2.另外我怎樣才能防止行的默認擴展。

查看:

@(Html.Kendo().Grid<KendoUI.Models.EmployeeViewModel>() 
      .Name("grid") 
      .Columns(columns => 
      { 
       columns.Bound(p => p.name).Title("Name"); 
       columns.Bound(p => p.gender).Title("Gender"); 
       columns.Bound(p => p.designation).Title("Designation").Width("300px"); 
       columns.Bound(p => p.department).Title("Department").Width("300px"); 
      }) 
      .ClientDetailTemplateId("template") 
      .HtmlAttributes(new { style = "height:430px;" }) 
      .Pageable() 
      .Navigatable() 
      .Sortable() 
      .Scrollable() 
      .DataSource(dataSource => dataSource // Configure the grid data source 
      .Ajax() 
      .Model(model => 
      { 
       model.Id(x => x.id); 
      }) 
      .Read(read => read.Action("Employee_Read", "Home")) // Set the action method which will return the data in JSON format 
      ) 
      .Events(events => events.DataBound("dataBound")) 
     ) 

<script id="template" type="text/kendo-tmpl"> 
    @(Html.Kendo().Grid<KendoUI.Models.EmployeeViewModel>() 
      .Name("grid_#id#") 
      .Columns(columns => 
      { 
       columns.Bound(p => p.id).Width(70); 
       columns.Bound(p => p.name).Width(110); 
       columns.Bound(p => p.gender).Width(110); 
      }) 
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .PageSize(5) 
       .Read(read => read.Action("Department_Read", "Home", new { employeeID = "#=id#" })) 
      ) 
      .Pageable() 
      .Sortable() 
      .ToClientTemplate() 
    ) 
    </script> 
    <script> 
     function dataBound() { 
      this.expandRow(this.tbody.find("tr.k-master-row").first()); 
     } 
    </script> 

控制器:

public ActionResult Employee_Read([DataSourceRequest]DataSourceRequest request) 
     { 
      //code for grid 
      return Json(result, JsonRequestBehavior.AllowGet); 
     } 

public ActionResult Department_Read(Int32 employeeID, [DataSourceRequest]DataSourceRequest request) 
     { 
      // Code for hierarchy grid detail 
      return Json(result, JsonRequestBehavior.AllowGet); 
     } 
+0

你有什麼成功? – Steve

回答

0
  1. 你在你的細節模板 犯了一個錯誤,你應該使用的.Name("grid_#=id#")代替.Name("grid_#id#")的 '=' 事項使用所有層次結構網格共享相同的ID所以每次只刷新第一個網格。
  2. 您的數據綁定()函數導致第一的默認擴展功能(每次網格綁定到數據源它。)
相關問題