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.
Unfortunately, activation email could not send to your email. Please try again.

Default SortDirection

Thread ID:

Created:

Updated:

Platform:

Replies:

131886 Aug 1,2017 02:57 PM Aug 8,2017 08:11 AM WPF 3
loading
Tags: SfDataGrid
Luca Spolidoro
Asked On August 1, 2017 02:57 PM

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 09:45 AM

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); 
                this.datagrid.View.SortDescriptions.Remove(sortcolumn); 
                this.datagrid.View.SortDescriptions.Add(sortDescription);              
            } 
        } 
        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; 
            } 
        }              
 
 
 
 
Regards, 
Srinivasan 
 


Luca Spolidoro
Replied On August 7, 2017 01:48 PM

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 08:11 AM

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


CONFIRMATION

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.

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.

;