We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GDBG. Nested tables and sorting

Hi all. I have two related tables in my dataset. How can I sort second table when user clicks on the columns headers?

1 Reply

AD Administrator Syncfusion Team June 23, 2004 12:36 PM UTC

The child lists are only know while the parent node is expanded. So, you would have to dynamically sort the ChildList as the node is expanded. And when your user clicks on a child column header, you would have to go through all grid rows, sorting any childtable that is visible. Here is code that sorts a column named "Name" when a row is expanded.
private void gridDataBoundGrid1_RowExpanded(object sender, GridRowEventArgs e)
{
	GridBoundRecordState rs = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
	DataView dv = rs.ChildList as DataView;
	if(dv != null)
	{
		dv.Sort = "Name";
		this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Rows(e.RowIndex + 1, e.RowIndex + rs.ChildCount));
	}
}
So, on a cellclick, you would have to check to see if it was on one of your child headers, and if so, set a paramater (to play the role of "Name") in the above code so that when nodes are opened in the future, you would sort that column. You would also want to loop through all the rows in your grid, getting each GridBoundRecodState for each row, and use the same code as above to sort any child tables already opened.

Loader.
Live Chat Icon For mobile
Up arrow icon