Sort filter entries
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
SIGN IN To post a reply.
7 Replies
SV
Srinivasan Vasu
Syncfusion Team
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.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SfGridDemo1598602482.zip
Please refer the below UG link to know about custom sorting.
UG Link: https://help.syncfusion.com/wpf/sfdatagrid/sorting?cs-save-lang=1&cs-lang=xaml#custom-sorting
Regards,
Srinivasan
BE
Bernd
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
SV
Srinivasan Vasu
Syncfusion Team
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.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SfGridDemo_Sample-311619201.zip
If your requirement is differ from this, please provide more details about your query.
Regards,
Srinivasan
BE
Bernd
November 30, 2016 07:41 PM UTC
Hi Srinivasan,
Attachment: FilterSorting_fbda22dd.zip
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
SV
Srinivasan Vasu
Syncfusion Team
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; }
} |
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SfGridDemo_(2)-1449811551.zip
Please refer the below UG Link to know about events for Filtering.
Regards,
Srinivasan
BE
Bernd
December 3, 2016 09:25 PM UTC
Hi Srinivasan,
yes, that's been it, thank you very much.
Regards
Bernd
BR
Balamurugan Rajaraman
Syncfusion Team
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.
SIGN IN To post a reply.
- 7 Replies
- 3 Participants
-
BE Bernd
- Nov 23, 2016 07:35 PM UTC
- Dec 5, 2016 08:46 AM UTC