Xuni Controls > CollectionView > Features > Sorting |
Xuni CollectionView interface supports ascending and descending sorting for data controls. To enable sorting, add one or more XuniSortDescription objects to the CollectionView's SortDescriptions property. To sort columns at runtime, You can simply tap the header of the list to sort data.
XuniSortDescription objects are flexible, they allow you to add objects for individual columns, and set their sorting order to ascending or descending.
The image below shows how the FlexGrid appears after sorting is applied to the column Name.
The following code example demonstrates how to sort a FlexGrid control in C# and XAML. This example uses the sample created in the FlexGrid's Quick Start section.
Import the following references in the class:
|
C# |
Copy Code |
---|---|
public static FlexGrid GetGrid() { var dataCollection = Customer.GetCustomerList(10); XuniCollectionView<Customer> cv = new XuniCollectionView<Customer>(dataCollection); var sort = cv.SortDescriptions.FirstOrDefault(sd => sd.SortPath == "Name"); var direction = sort != null ? sort.Direction : SortDirection.Descending; cv.SortAsync(x => x.Name, direction == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending); FlexGrid _grid = new FlexGrid(); _grid.ItemsSource = cv; _grid.VerticalOptions = LayoutOptions.FillAndExpand; return _grid; cv.SortChanged += cv_SortChanged; } static void cv_SortChanged(object sender, EventArgs e) { throw new NotImplementedException(); } |
XAML |
Copy Code |
---|---|
<xuni:FlexGrid AllowSorting="True"> |