If you work in hierarchy mode, you can define when the data binding 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 - data binding of a child GridTableView will
only take place when an item is expanded. This is the default value.
- HierarchyLoadMode.Client is similar to HierarchyLoadMode.ServerBind
but the 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 the
GridTableView.HierarchyLoadMode property value impacts the performance
in 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 for 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.
Using different load modes in Telerik RadGrid
As
HierarchyLoadMode is a GridTableView setting (not RadGrid property),
you can even fine tune further 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 above 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 expand and the second level uses server-side mode (HierarchyLoadMode.ServerBind).