WebHierarchicalDataGrid™ sorting is a behavior that enables you to sort columns. You can have single or multiple column sorting.
You will enable column sorting for parent and child levels in WebHierarchicalDataGrid at design time.
Bind WebHierarchicalDataGrid to a WebHierarchicalDataSource™ component retrieving data from the Categories and Products table. For more information on doing this, see the Binding to Hierarchical Data Source topic.
In the Microsoft® Visual Studio property window, locate the Behaviors property and click the ellipsis (…) button to launch the Behaviors Editor dialog.
Check the checkbox next to Sorting from the list of behaviors on the left to enable the behavior.
Leave SortingMode as Single in the properties.
Set EnableInheritance property to True. This enables all the child levels to automatically inherit Sorting behavior. The property’s default value is False.
Click Apply and OK to close the dialog window.
Run the application. You can sort one column at a time in WebHierarchicalDataGrid. The child band can also be sorted.
You can sort WebHierarchicalDataGrid using server-side or client-side code. On the server side, you have the SortedColumns property. In this topic, the RowIslandDataBinding event is handled to sort parent and child columns.
On the client, you have the sortColumn method to use. The sortColumn method requires the column name and the sort direction parameters. The Sort direction is 0, 1, or 2 for none, ascending, or descending. The RowExpanded client event can be handled to sort a column in the child level.
The following code shows you how to sort a column in WebHierarchicalDataGrid, assuming sorting is enabled and its EnableInheritance property set to true.
In Visual Basic:
' Hook up RowIslandDataBinding event AddHandler Me.WebHierarchicalDataGrid1.RowIslandDataBinding, AddressOf WebHierarchicalDataGrid1_RowIslandDataBinding Private Sub WebHierarchicalDataGrid1_RowIslandDataBinding(ByVal sender As Object, ByVal e As RowIslandEventArgs) Handles WebHierarchicalDataGrid1.RowIslandDataBinding ' Sort a Column in PARENT BAND If e.RowIsland.DataMember = "SqlDataSource1_DefaultView" Then Dim sort As Sorting = e.RowIsland.Behaviors.Sorting sort.SortedColumns.Add("CategoryName", Infragistics.Web.UI.SortDirection.Descending) End If ' Sort a Column in CHILD BAND If e.RowIsland.DataMember = "SqlDataSource2_DefaultView" AndAlso e.RowIsland.ParentRow = Me.WebHierarchicalDataGrid1.GridView.Rows(1) Then Dim sort As Sorting = e.RowIsland.Behaviors.Sorting sort.SortedColumns.Add(e.RowIsland.Columns(1), Infragistics.Web.UI.SortDirection.Ascending) End If End Sub
In C#:
// Hook up RowIslandDataBinding event this.WebHierarchicalDataGrid1.RowIslandDataBinding += new RowIslandEventHandler(WebHierarchicalDataGrid1_RowIslandDataBinding); void WebHierarchicalDataGrid1_RowIslandDataBinding(object sender, RowIslandEventArgs e) { // Sort a Column in PARENT BAND if (e.RowIsland.DataMember == "SqlDataSource1_DefaultView") { Sorting sort = e.RowIsland.Behaviors.Sorting; sort.SortedColumns.Add("CategoryName", Infragistics.Web.UI.SortDirection.Descending); } // Sort a Column in CHILD BAND if (e.RowIsland.DataMember == "SqlDataSource2_DefaultView" && e.RowIsland.ParentRow == this.WebHierarchicalDataGrid1.GridView.Rows[1]) { Sorting sort = e.RowIsland.Behaviors.Sorting; sort.SortedColumns.Add(e.RowIsland.Columns[1], Infragistics.Web.UI.SortDirection.Ascending); } }
In Javascript:
var grid = $find("WebHierarchicalDataGrid1"); // Sort a COLUMN IN PARENT BAND var parentGrid = grid.get_gridView(); if (parentGrid != null) parentGrid.get_behaviors().get_sorting().sortColumn(parentGrid.get_columns().get_columnFromKey("CategoryName"), 2, false); // Sort a COLUMN IN CHILD BAND var childGrid = grid.get_gridView().get_rows().get_row(0).get_rowIslands(0)[0]; if (childGrid != null) childGrid.get_behaviors().get_sorting().sortColumn(childGrid.get_columns().get_columnFromKey("ProductName"), 2, false);