0
我想在telerik/kendo網格中顯示分層數據。數據來自數據庫視圖(導入爲模型),其中包含電氣中斷列表。主鍵是interruptID在視圖中有一個名爲ParentOutage的字段,如果填充了另一箇中斷的InterruptionID,則會與2條記錄相關聯。我跟着Telerik的例子/演示到信,但我不能讓網格顯示任何兒童記錄。填充子記錄的事件永遠不會觸發。我已經試着對傳遞給getChildOutages函數的值進行硬編碼,以查看是否存在問題,但仍未解僱。網格中的每一行都會出現箭頭以展開記錄,但是當您展開它時,只會出現一個小空白區域。也只有少數記錄具有子記錄,因此箭頭不應出現在每條記錄旁邊。我已爲我下面的代碼:Telerik MVC Grid Hierarchy - 沒有兒童記錄
<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>
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
首先,我強烈建議改進此帖子的縮進。其次,在試圖展開一行時,你是否在控制檯窗口中看到任何錯誤? – Sandman
抱歉,縮進 - Visual Studio似乎無法正確處理剃鬚刀代碼/ html,並總是弄亂我的縮進 - 我修復它們,然後回到原來的樣子。我能夠解決問題併發布答案。 – PlasmaX