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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sort filter entries

Thread ID:

Created:

Updated:

Platform:

Replies:

127568 Nov 23,2016 07:35 PM UTC Dec 5,2016 08:46 AM UTC WPF 7
loading
Tags: SfDataGrid
Bernd
Asked On November 23, 2016 07:35 PM UTC

Hi,

 I was wondering if it was possible to apply a custom sort order to the the SfDataGrid filter items in the built-In checkbox filter UI.

Regards
Bernd

Srinivasan Vasu [Syncfusion]
Replied On November 24, 2016 01:34 PM UTC

Hi Bernd, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query and we have prepared a sample based on requirement. SfDataGrid allows you to sort the columns based on the custom logic. The custom sorting can be applied by adding the SortComparer instance to SfDataGrid.SortComparers. 
 
 
Please refer the below UG link to know about custom sorting. 
 
 
 
Regards, 
Srinivasan 


Bernd
Replied On November 24, 2016 02:16 PM UTC

Srinivasan,

thank you for your reply.

I do understand custom sorting but I do want to achieve something different:

I have a table of entries with a name and a custom SortIndex, i.e.

Apple, 2
Peach, 1
Cherry, 3

In the standard grid view I can have a column with the SortIndex to sort according to it but when using the filter UI the items are always sorted alphabetically (Apple > Cherry > Peach). But I do want to sort by the SortIndex (Peach > Apple > Cherry).

Regards
Bernd




Srinivasan Vasu [Syncfusion]
Replied On November 25, 2016 01:57 PM UTC

Hi Bernd, 
 
We have prepared a sample based on your requirement. When we sorted the Name column, which is sorted based on SortIndex property in SfDataGrid. 
 
Please download the sample from the below location. 
 
 
If your requirement is differ from this, please provide more details about your query. 
 
 
Regards, 
Srinivasan 
 


Bernd
Replied On November 30, 2016 07:41 PM UTC

Hi Srinivasan,

this is not whatr I am trying to do. I want to sort the list within the FilterUI. I attached a screen shot to demonstrate the need.

Regards
Bernd

Attachment: FilterSorting_fbda22dd.zip

Srinivasan Vasu [Syncfusion]
Replied On December 2, 2016 07:21 AM UTC

Hi Bernd, 
 
You can achieve your requirement by using SfDataGrid.FilterItemsPopulated event. 
 
Please refer the below code example. 
 
C# 
   public MainWindow() 
        { 
            InitializeComponent(); 
            itemsSource = new List<FilterElement>();                        
            this.sfDataGrid.FilterItemsPopulated += sfDataGrid_FilterItemsPopulated; 
        } 
 
        void sfDataGrid_FilterItemsPopulated(object sender, GridFilterItemsPopulatedEventArgs e) 
        { 
 
            var model = (sender as SfDataGrid).DataContext as ViewModel; 
            var collection = model.GridRowCollection.OrderBy(xy => xy.Sortindex); 
            var distinctRecords = collection.Select(x => x.Name).Distinct(); 
            this.ItemsSource = distinctRecords.Select(item => 
                                                                 new FilterElement 
                                                                 {                                                                     
                                                                     ActualValue = item,  
                                                                     DisplayText = item, 
                                                                 }).ToList(); 
            e.ItemsSource = this.ItemsSource;             
        }                                                               
 
        private List<FilterElement> itemsSource; 
        public List<FilterElement> ItemsSource 
        { 
            get { return itemsSource; } 
            set { this.itemsSource = value; } 
        } 
 
 
Please refer the below UG Link to know about events for Filtering. 
 
 
 
Regards, 
Srinivasan 
 


Bernd
Replied On December 3, 2016 09:25 PM UTC

Hi Srinivasan,

yes, that's been it, thank you very much.

Regards
Bernd

Balamurugan Rajaraman [Syncfusion]
Replied On December 5, 2016 08:46 AM UTC

Hi Bernd, 
Thanks for your update, please let us know if you have any further assistance. 
Regards, 
Balamurugan. 


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.

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

;