If you work in hierarchy mode, you can define when the DataBind for GridTableView will occur. In order to do this, you need to set the following property:
GridTableView.HierarchyLoadMode
The possible values are:
- HierarchyLoadMode.ServerBind - all child GridTableViews will be bound immediately when DataBind occurs for a parent GridTableView or RadGrid.
- HierarchyLoadMode.ServerOnDemand - DataBind of a child GridTableView would only take place when an item is Expanded (see GridItem.Expanded). This is the default value.
- HierarchyLoadMode.Client is similar to HierarchyLoadMode.ServerBind, but items are expanded client-side, using JavaScript manipulations, instead of postback to the server.
In order to use client-side hierarchy expand, you will need to set also ClientSettings.AllowExpand.Collapse to true.
Changing this property value impacts the performance the following way:
- In HierarchyLoadMode.ServerBind mode:
-
- The roundtrip to the database happens only once - when the grid is bound.
- The ViewState holds all data for the detail tables.
- Only detail table-views of the expanded items are rendered.
- You need to postback to the server to in order to expand an item.
- In HierarchyLoadMode.ServerOnDemand mode:
-
- The roundtrip to the database happens when the grid is bound and when an item is expanded.
- The ViewState holds data only for the visible Items (the smallest possible ViewState).
- Only detail table-views of the expanded items are rendered.
- You need to postback to the server in order to expand an item.
- In HierarchyLoadMode.Client mode:
-
- The roundtrip to the database happens only when grid is bound.
- The ViewState holds all detail tables data.
- All items are rendered - even if not visible (not expanded).
- No postback to the server is needed to expand an item - expand/collapse of hierarchy items is managed client-side.
- Note: when setting HierarchyLoadMode = Client you should also set ClientSettings -> AllowExpandCollapse = true for your grid instance. Furthermore, a requirement in client hierarchy load mode is to have ShowHeader = true for tables in order to expand/collapse the items in them which has child items.
We will do everything possible to address the issue with the header visibility for child tables and HierarchyLoadMode = "Client" in one of the next versions of the grid. However, the visible column headers take a major part in the grid internal mechanism for client-side hierarchy expand/collapse. Fortunately, there is a workaround available even now:
- wire the ItemCreated event of the grid
- check whether the item is of type GridHeaderItem and belongs to inner table
- set its display style attribute to none
| VB.NET |
Copy Code |
|
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemCreated If (TypeOf e.Item Is GridHeaderItem AndAlso e.Item.OwnerTableView.DataSourceID = "MyInnerTableDataSourceID") Then Dim headerItem As GridHeaderItem = CType(e.Item, GridHeaderItem) headerItem.Style( "display") = "none" End If End Sub |
| C# |
Copy Code |
|
private void RadGrid1_ItemCreated(object sender, Telerik.WebControls.GridItemEventArgs e) { if (e.Item is GridHeaderItem && e.Item.OwnerTableView.DataSourceID == "MyInnerTableDataSourceID") { GridHeaderItem headerItem = e.Item as GridHeaderItem; headerItem.Style[ "display"] = "none"; } } |
Further details about the hierarchy load modes of Telerik RadGrid and how to use them to optimize the control's performance you can find here.
Using different load modes in Telerik RadGrid
As HierarchyLoadMode is a GridTableView setting (not RadGrid property) you can even more fine tune the way that Telerik RadGrid handles loading of hierarchy tables. You can set HierarchyLoadMode.Client for tables that need fast view and HierarchyLoadMode.ServerBind for tables that are less likely to be accessed.
Thus you can balance the loading of the grid between:
- the client - this will require more bandwidth but will assure less load to the server and database and quicker expand.
- the server - will save some client-load for the inner tables of the grid.
The example below shows the advanced hierarchy model of Telerik RadGrid with mixed mode expand/collapse (client-side and server-side). A three level hierarchy is demonstrated with Customer Master Table and two nested Detail Tables: Orders and OrderDetails. The first level of hierarchy uses client-side (HierarchyLoadMode.Client) expand and the second level uses server-side mode (HierarchyLoadMode.ServerBind)
