Ajax Data Binding
The PanelBar provides support for remote data binding by using a DataSource configuration object.
When using remote data binding, the PanelBar implements lazy loading for hierarchical data. When an item is expanded, its child items are requested from the server through an additional Read request. The id of the expanded item is sent as a parameter in the Read request, allowing the server to filter and return only the relevant child items back to the PanelBar. This approach ensures optimal performance by loading data on-demand as users navigate through the hierarchy.
The following example shows how to configure the DataSource of the PanelBar for remote data binding.
@(Html.Kendo().PanelBar()
.Name("panelbar")
.DataTextField("Name")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("Read_PanelBarData", "Home")
)
)
)By default, the PanelBar shows an expand icon if the dataItem has a property named
hasChildrenand it evaluates totrue. You can either ensure data is mapped as demonstrated above, or configure the mapping through theDataSourceconfiguration.
@(Html.Kendo().PanelBar()
.Name("panelbar")
.DataTextField("Name")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("Read_PanelBarData", "Home")
)
.Model(m=> {
m.HasChildren("HasNestedItemsField");
})
)
)Troubleshooting Remote Loading
The PanelBar supports two remote loading scenarios:
- Remote hierarchical data—The
DataSourcesends aReadrequest for the root items and for the children of an expanded item. Inspect the request in the browser developer tools and verify that the response contains the configured text field, the itemid, thehasChildrenvalue, and the children for the requested parent. - Remote HTML content—The
LoadContentFrommethod or thecontent-urlattribute loads HTML into an item when it is expanded. Verify that the content URL returns HTML and that the item's content<div>is empty before the request is made. For more information, see Loading Content with AJAX in the PanelBar.
For remote hierarchical data, you can customize the loading and retry messages and handle DataSource errors:
@(Html.Kendo().PanelBar()
.Name("panelbar")
.Messages(messages => messages
.Loading("Loading items...")
.RequestFailed("Request failed.")
.Retry("Retry")
)
.Events(events => events.Error("onError"))
)
<script>
function onError(e) {
console.error(e);
}
</script>The Messages settings and built-in retry behavior apply to DataSource binding failures. For remote HTML content requests, use the contentLoad and error events where supported and inspect the network response. The PanelBar error event does not fire with jQuery 3.x. For more information, see PanelBar Data Binding and the PanelBar API Reference.