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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Default SortDirection

Thread ID:





131886 Aug 1,2017 06:57 PM UTC Aug 8,2017 12:11 PM UTC WPF 3
Tags: SfDataGrid
Luca Spolidoro
Asked On August 1, 2017 06:57 PM UTC

When I click on a column to sort, the default SortDirection is Ascending.
I would like that the first time I click on any column, the default SortDirection is Descending.

Is it possible to achieve that?

Srinivasan Vasu [Syncfusion]
Replied On August 2, 2017 01:45 PM UTC

Hi Luca, 
Thanks for contacting Syncfusion support. 
We have checked your query and we have prepared a sample as per your requirement. You can achieve your requirement by using SfDataGrid.SortColumnsChanging and SfDataGrid.SortColumnsChanged event. 
Please refer the below code example. 
        this.datagrid.SortColumnsChanging += Datagrid_SortColumnsChanging; 
        this.datagrid.SortColumnsChanged += Datagrid_SortColumnsChanged; 
  private void Datagrid_SortColumnsChanged(object sender, GridSortColumnsChangedEventArgs e) 
            // Here, we have updated the column's items in view based on SortDescriptions. 
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
                var sortcolumn = this.datagrid.View.SortDescriptions.FirstOrDefault(x => x.PropertyName == e.AddedItems[0].ColumnName); 
                var sortDescription = new SortDescription(sortcolumn.PropertyName, ListSortDirection.Descending); 
        private void Datagrid_SortColumnsChanging(object sender, GridSortColumnsChangingEventArgs e) 
            // Initially, we can change the SortDirection of particular column based on columnchanged action. 
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
                e.AddedItems[0].SortDirection = ListSortDirection.Descending; 

Luca Spolidoro
Replied On August 7, 2017 05:48 PM UTC

Hello Srinivasan,

this is a perfect solution! I think it should be added to the official guide: https://help.syncfusion.com/wpf/sfdatagrid/sorting

Balamurugan Rajaraman [Syncfusion]
Replied On August 8, 2017 12:11 PM UTC

Hi Luca, 
Thanks for the update. 
We will consider your suggestion and include this in to our documentation. 
Balamurugan R 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon