2X faster development
The ultimate WPF UI toolkit to boost your development speed.
WPF DataGrid (SfDataGrid) allows you to sort the data against one or more columns either in ascending or descending order. The sorting can be performed by clicking a column header. You can enable/disable the sorting for all the columns in DataGrid by using DataGrid.AllowSorting property. Moreover, you can also enable/disable the sorting for a particular column by using Column.AllowSorting. <syncfusion:SfDataGrid x:Name="dataGrid" AllowSorting="True" ItemsSource="{Binding Orders}"> </syncfusion:SfDataGrid>
Programmatic sortingYou can sort a column in programmatic way by using the DataGrid.SortColumnDescriptions property. <syncfusion:SfDataGrid.SortColumnDescriptions> <syncfusion:SortColumnDescription ColumnName="OrderID" SortDirection="Ascending" /> <syncfusion:SortColumnDescription ColumnName="CustomerName" SortDirection="Descending" /> </syncfusion:SfDataGrid.SortColumnDescriptions>
Showing sort order numbersWPF DataGrid (SfDataGrid) allows you to sort the data against one or more columns by clicking a column header by pressing <kbd>Ctrl</kbd> key. Sorting orders to denote the order of sorting performed for columns can be enabled by using the DataGrid.ShowSortNumbers property. <syncfusion:SfDataGrid x:Name="dataGrid" AllowSorting="True" ShowSortNumbers="True" ItemsSource="{Binding Orders}"> </syncfusion:SfDataGrid>
Tristate sortingThe data is sorted in ascending or descending order when clicking a column header. Data can be rearranged to its initial order from descending, when clicking column header by setting SfDataGrid.AllowTriStateSorting property. Following are the sequence of sorting orders when clicking column header,
<syncfusion:SfDataGrid x:Name="dataGrid" AllowSorting="True" AllowTriStateSorting="True" ItemsSource="{Binding Orders}"> </syncfusion:SfDataGrid>
Custom SortingColumns can be sorted based on the custom logic. The custom sorting can be applied by adding the SortComparer instance to SfDataGrid.SortComparers. You can go through this user guide to know more about custom sorting. EventsYou can change the sorting behavior using SfDataGrid.SortColumnsChanging and SfDataGrid.SortColumnsChanged event in DataGrid. The SortColumnsChanging event occurs while sorting the columns by clicking a column header. The SortColumnsChanged event occurs when the sorting is applied to the column. dataGrid.SortColumnsChanging += DataGrid_SortColumnsChanging; private void DataGrid_SortColumnsChanging(object sender, Syncfusion.UI.Xaml.Grid.GridSortColumnsChangingEventArgs e) { // Do your customization here } dataGrid.SortColumnsChanged += DataGrid_SortColumnsChanged; private void DataGrid_SortColumnsChanged(object sender, Syncfusion.UI.Xaml.Grid.GridSortColumnsChangedEventArgs e) { // Do your customization here }
Take a moment to peruse the documentation, where you can find about sorting, with code examples. Please refer this link to know about the essential features of Syncfusion WPF DataGrid. View WPF DataGrid Sorting Demo in GitHub
|
2X faster development
The ultimate WPF UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.