Sort ColumnFilter DisplayText alphabetial

Hey,
when using ColumnFilter "DisplayText" the entries are sorted by the values that are behind the DisplayText.
For excample:
ID Name
1 Marco
2 Polo
3 Beta
4 Gamma
Will be in that exact same order. I would like to have the alphabetical order: Beta, Gamma, Marco, Polo.
Is this possible? I'm using data from an Entity Framework viewmodel with an underlying SQL Server Database.

9 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team December 1, 2020 09:02 AM UTC

Hi Timo, 

Thanks for contacting Syncfusion support.  

We are little unclear with your requirement. However we suspect that your requirement is to sort a column based on its display value. You can achieve this requirement by setting GridColumn.SortMode  property of the specific column as Display as shown in the following code example. 

Code example :  

<syncfusion:GridTextColumn MappingName="FirstName" SortMode="Display" /> 


Please revert to us with more details if we have misunderstood your requirement.  

Regards, 
Mohanram A. 



TS Timo Schulte December 1, 2020 09:21 AM UTC

Thank you for the reply!
I have a GridComboBox with underlying value as ID and the display value is from a converter that basically parses two columns together. I want to sort the excel like filter by the display text. SortMode="Display" isn't working.

<syncfusion:GridComboBoxColumn x:Name="cbGeraeteModellName" MappingName="Modell_ID" DisplayBinding="{Binding Modelle, Converter={StaticResource grModell}}" DisplayMemberPath="Modellname" HeaderText="Modell" AllowEditing="True" AllowFiltering="True" SelectedValuePath="Id" ColumnFilter="DisplayText" SortMode="Display"/>

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Modelle m = value as Modelle;

            if(value is null || m is null)
            {
                return null;
            }

            return m.Hersteller + " " + m.Modellname;
        }




MA Mohanram Anbukkarasu Syncfusion Team December 2, 2020 01:48 PM UTC

Hi Timo, 

Thanks for the update.  

We are able to understand your requirement to sort the items displayed in the FilterControl based on the display value. SfDataGrid doesn’t have any direct support to  achieve this requirement. However we are checking the feasibility to achieve this by any workaround. We will check and update with further details on 4th December 2020. We appreciate your patience until then. 

Regards, 
Mohanram A 



MA Mohanram Anbukkarasu Syncfusion Team December 5, 2020 06:34 AM UTC

Hi Timo, 

Sorry for the inconvenience. 

We are still validating this. We will check and update with further details on 8th December 2020. We appreciate your patience and understanding. 

Regards, 
Mohanram A. 



TS Timo Schulte December 5, 2020 12:18 PM UTC

Thanks for the update!


MA Mohanram Anbukkarasu Syncfusion Team December 7, 2020 01:00 PM UTC

Hi Timo,  

Thanks for the update.  

We will update with details on 8th December as promised.  

Regards, 
Mohanram A. 



MA Mohanram Anbukkarasu Syncfusion Team December 8, 2020 10:59 AM UTC

Hi Timo, 

Thanks for your patience.  

You can achieve your requirement to sort the elements displayed in the FilterControl based on the display value by using the event SfDataGrid.FilterItemsPopulated as shown in the following code example.  

Code example :  

<syncfusion:SfDataGrid Name="dataGrid" 
                       AutoGenerateColumns="False" 
                       ItemsSource="{Binding Employees}" 
                       AllowFiltering="True" 
                       FilterItemsPopulated="DataGrid_FilterItemsPopulated"> 
 
private void DataGrid_FilterItemsPopulated(object sender, Syncfusion.UI.Xaml.Grid.GridFilterItemsPopulatedEventArgs e) 
{ 
    (e.ItemsSource as List<FilterElement>).Sort(new FilterElementComparer()); 
} 
 
public class FilterElementComparer : IComparer<FilterElement> 
{ 
    public int Compare(FilterElement x, FilterElement y) 
    { 
        if (x == null) 
        { 
            if (y == null) 
            { 
                // If x is null and y is null, they're 
                // equal. 
                return 0; 
            } 
            else 
            { 
                // If x is null and y is not null, y 
                // is greater. 
                return -1; 
            } 
        } 
        else 
        { 
            // If x is not null... 
            // 
            if (y == null) 
            // ...and y is null, x is greater. 
            { 
                return 1; 
            } 
            else 
            { 
                 
                return x.DisplayText.CompareTo(y.DisplayText); 
                 
            } 
        } 
    } 
} 


We have prepared a simple sample using the above given code example to replicate your scenario and it is available in the following link for your reference.  


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

TS Timo Schulte December 8, 2020 02:48 PM UTC

Working as expected. Thank you very much.


MA Mohanram Anbukkarasu Syncfusion Team December 9, 2020 12:58 PM UTC

Hi Timo, 

Thanks for the update.  

We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon