Sorting is way to organize data in ascending or descending order based on certain criteria such as numeric, alphabetical, etc. Sorted data is generally easier to understand and maintain. In FlexReport, sorting is achieved by using the SortDefinitions collection of the DataSource class.
Suppose you want to view the list of products with their names in ascending order. In this case, the list should be sorted by Name column. Perform the following steps to illustrate how to sort the names in the list of products in alphabetical order.
C# |
Copy Code
|
---|---|
<c1:C1FlexViewer Name="flexsortViewer" HorizontalAlignment="Left" Height="633" VerticalAlignment="Top" Width="958" Margin="0,28,0,0"/> <Button x:Name="btnsort" Content="Sort Products by Name" Click="btnsort_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="191" Margin="300,5,0,0"/> |
C# |
Copy Code
|
---|---|
Boolean asc = true; if (asc == true) { SortDefinition sd = new SortDefinition("[Name]", SortDirection.Ascending); flexReport.DataSource.SortDefinitions.Add(sd); asc = false; flexReport.Render(); } |