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.
- HierarchyLoadMode.Conditional is mix of HierarchyLoadMode.ServerOnDemand and HierarchyLoadMode.ClientBind, with the difference that when an item is expanded once and postback fires for the initial expand, next time the same item will be expanded on the client . This behavior is also persisted across postback to the server-so if you have previously expanded an item from then on it will only be expanded / collapsed on the client regardless of how many postbacks you perform. The behavior is the same if you have previously loaded hierarchy with expanded items (e.g. setting Expanded to true in the PreRender event)-these expanded items will also be collapsed / expanded on the client.
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.Conditional mode:
- The roundtrip to the database happens when the grid is bound and when an item is expanded first time.
- The ViewState holds data only for the visible Items.
- Only detail table-views of the expanded items are rendered.
- You need to postback to the server in order to expand an item first time and after that for expanding already expanded item no postback to the server is needed - expand/collapse of hierarchy items is managed client-side.
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.
This example shows the advanced hierarchy model of Telerik RadGrid with client-side expand/collapse. A three level hierarchy is demonstrated with Customer Master Table and two nested Detail Tables - Orders and OrderDetails. All grid levels have set
GridTableView.HierarchyLoadMode.Client.