SelfReference makes a simple flat grid becomes hierarchical. It is because of the reference from one column to another based on the DataMember in it. There are numerous UI settings applicable to this feature, such as TreeView selection mode, parent root mode, AutoFit column on expand, and more.
You bind data the same way as you usually do in a normal flat table. The grid will then be able to automatically group the child rows based on SelfReferenceSettings. This feature works perfectly in conjunction with all existing features such as sorting, grouping and so on.
Based on the picture above, WebGrid.NET designer provides a collection of settings called SelfReferenceSettings. These settings will reflect to WebGrid's SelfReference feature.
- ChildDataMember = ChildDataMember is a property to set a child's data member that will be referred to the parent.
- Enabled = Enabled is a property to set the whether the SelfReference is enabled or not.
- ExpandColumnInnerTextPadding = ExpandColumnInnerTextPadding is a property to specify the padding for expand column's inner text area.
- ExpandColumnMember = ExpandColumnMember is a property to specify where the expand/collapse icon will be rendered.
- FitColumnOnExpand = FitColumnOnExpand is a property to automatically set best fit when expanded.
- IsTreeViewSelectionMode = IsTreeViewSelectionMode is a property to specify whether the selection mode will use TreeView-like selection.
- LoadOnDemand = LoadOnDemand is a property to specify whether child rows will be populated on demand.
- ParentDataMember = ParentDataMember is a property to set parent data member of self referencing table.
- TreatOrphanRecordAsRoot = TreatOrphanRecordAsRoot is a property to determine whether rows that doesn't have parent or child will be treated as root.
The picture belows will show how the SelfReference works.
FirstName is an ExpandColumnMember, EmployeeID is a ParentDataMember, and ReportsTo is a ChildDataMember. Please don't forget to enable the Enabled property at the SelfReferenceSettings.
Please take a look carefully at the FirstName, EmployeeID, and ReportsTo columns. EmployeeID has 2 as a DataMember, and it will be a parent for some of ReportsTo column DataMember that has 2 as the values, and so on. FirstName column will be added a + icon to expand the self reference hierarchy and - icon to collapse.
Getting Started
Getting Started
Overview
WebGrid Features Overview
Other Resources
Walkthrough Topics
How-to Topics