我正在尝试在telerik / kendo网格中显示分层数据。数据来自数据库视图(作为模型导入),其中包含电气中断列表。主键是interruptionID视图中有一个名为ParentOutage的字段,如果填充了另一个中断的InterruptionID,则会关联2条记录。我跟着Telerik的示例/演示到了这封信但我无法让网格显示任何子记录。填充子记录的事件永远不会触发。我已经尝试对传递给getChildOutages函数的值进行硬编码,以查看是否存在问题,但它仍然没有被触发。网格中的每一行都显示箭头以展开记录,但当您展开它时,只会出现一个小空格。此外,只有少数记录具有子记录,因此箭头不应出现在每条记录旁边。我在下面发布了我的代码:
<div class="form-group">
@Code
Html.Kendo.Grid(Of vw_ElectInterruptions)() _
.Name("gridInterruptions") _
.Columns(Sub(c)
c.Bound(Function(p) p.InterruptionID).Width(75).Sortable(True).Title("ID")
c.Bound(Function(p) p.ParentOutage).Width(85).Sortable(True).Title("Parent ID")
c.Bound(Function(p) p.Description).Width(175).Sortable(True).Title("Description")
c.Bound(Function(p) p.CircuitOrArea).Width(150).Sortable(True).Title("Area/Circuit")
c.Bound(Function(p) p.TimeOff).Width(100).Sortable(True).Title("TimeOff").Format("{0:dd-MMM-yy hh:mm}")
c.Bound(Function(p) p.TimeOn).Width(100).Sortable(True).Title("TimeOn").Format("{0:dd-MMM-yy hh:mm}")
End Sub) _
.Events(Function(e) e.DataBound("dataBound")) _
.ClientDetailTemplateId("template") _
.AutoBind(True) _
.Sortable(Sub(d) d.SortMode(GridSortMode.SingleColumn).AllowUnsort(False)) _
.Filterable() _
.HtmlAttributes(New With {.Style = "height:500px;"}) _
.Pageable(Sub(d) d.PageSizes(True).ButtonCount(5).Refresh(True)) _
.DataSource(Sub(d)
d.Ajax() _
.Sort(Sub(sort)
sort.Add("TimeOff").Descending()
sort.Add("InterruptionID").Ascending()
End Sub) _
.PageSize(25) _
.ServerOperation(False) _
.Read(Function(read) read.Action("ElecInterruptionRefreshGrid", "Application")) _
.Events(Sub(e)
e.Error("grid_error")
End Sub)
End Sub).Render()
End Code
</div>
<script id="template" type="text/x-kendo-template">
@Code
Html.Kendo.Grid(Of vw_ElectInterruptions)() _
.Name("childInterruptions_#=InterruptionID#") _
.Columns(Sub(c)
c.Bound(Function(p) p.InterruptionID).Width(75).Sortable(True).Title("ID")
c.Bound(Function(p) p.Description).Width(175).Sortable(True).Title("Description")
c.Bound(Function(p) p.CircuitOrArea).Width(150).Sortable(True).Title("Area/Circuit")
c.Bound(Function(p) p.TimeOff).Width(100).Sortable(True).Title("TimeOff").Format("{0:dd-MMM-yy hh:mm}")
c.Bound(Function(p) p.TimeOn).Width(100).Sortable(True).Title("TimeOn").Format("{0:dd-MMM-yy hh:mm}")
End Sub) _
.DataSource(Sub(d)
d.Ajax() _
.Read(Function(read) read.Action("GetChildOutages", "Application", New With {.id = "#=InterruptionID#"}))
End Sub).ToClientTemplate()
End Code
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
&#13;
And the controller code:
Public Function ElecInterruptionRefreshGrid(request As DataSourceRequest) As ActionResult
Dim model = db.vw_ElectInterruptions.ToList
Dim jsonResult = Json(model.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)
jsonResult.MaxJsonLength = Int32.MaxValue
Return jsonResult
End Function
Public Function GetChildOutages(id As Integer, request As DataSourceRequest) As ActionResult
Dim model = db.vw_ElectInterruptions.Where(Function(w) w.ParentOutage = id).ToList
Dim jsonResult = Json(model.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)
jsonResult.MaxJsonLength = Int32.MaxValue
Return jsonResult
End Function
答案 0 :(得分:0)
好的,我花了好几个小时,然后在发布这个问题后的几分钟内找到答案。显然它并不像我将子网格模板放在@Code ... End Code - block中这样的事实。我将模板脚本更改为这样,并开始工作:
@(Html.Kendo.Grid(Of vw_ElectInterruptions)() _
.Name("childInterruptions_#=InterruptionID#") _
.Columns(Sub(c)
c.Bound(Function(p) p.InterruptionID).Width(75).Sortable(True).Title("ID")
c.Bound(Function(p) p.Description).Width(175).Sortable(True).Title("Description")
c.Bound(Function(p) p.CircuitOrArea).Width(150).Sortable(True).Title("Area/Circuit")
c.Bound(Function(p) p.TimeOff).Width(100).Sortable(True).Title("TimeOff").Format("{0:dd-MMM-yy hh:mm}")
c.Bound(Function(p) p.TimeOn).Width(100).Sortable(True).Title("TimeOn").Format("{0:dd-MMM-yy hh:mm}")
End Sub).AutoBind(True) _
.DataSource(Sub(d)
d.Ajax() _
.Read(Function(read) read.Action("GetChildOutages", "Application", New With {.id = "#=InterruptionID#"}))
End Sub).ToClientTemplate())
&#13;
不确定为什么会有所作为。