RadDataGrid set case-sensetice mode of to all columns

5 posts, 1 answers
  1. Petr
    Petr avatar
    5 posts
    Member since:
    Jul 2019

    Posted 19 Aug Link to this post

    Hello,

    I'm using a datagrid bound to an observable collection(autogenerate columns mode).
    I need to set all Column Filters to case insensetive mode(when user open filter of string column, case-sensetive mode will be off). I tryed to find it in documantation and here, but without any result. Please, can you help me.

    Thanks a lot,

    Petr
  2. Lance | Principal TSE
    Admin
    Lance | Principal TSE avatar
    1043 posts

    Posted 19 Aug Link to this post

    Hi Petr,

    This available as a built-in option, just click the case-sensitive button in the Text filter UI. Here's a screenshot:

    Custom Filter UI Control

    If you want that turned on by default, you'll need to do the following:

    1. Disable automatic column generation (set AutoGenerateColumns="False")
    2. Manually define the columns for your DataGrid
    3. Create a custom FilterControl
    4. Assign that custom FilterControl to the column(s) that need it.

    First, you'll want to carefully read the tutorial on how to use a custom FilterControl (specifically parts 3 and 4 will be what you'd be using). In your case, you can just extend our DataGridTextFilterControl and set the IsCaseSensitive to false:

    public class MyPresetTextFilterControl : DataGridTextFilterControl
    {
        public MyPresetTextFilterControl()
        {
            IsCaseSensitive = false;
        }
    }

    To be clear, you would be using MyPresetTextFilterControl instead of ColorFilterControl from the tutorial. To help clarify, I've done this custom work in the attached demo for your reference. The 2nd column uses the custom filter control.

    Regards, Lance | Technical Support Engineer, Principal
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Petr
    Petr avatar
    5 posts
    Member since:
    Jul 2019

    Posted 20 Aug in reply to Lance | Principal TSE Link to this post

    Hi Lance,

    Thank you very much for answer and help!
    I was expecting solution for case with auto generating column. Disable auto generating is not convinient for my task.
    But i realized that this option was not added and I can't use it in my case.

    Anyway thank you for help!

    Petr


  4. Answer
    Lance | Principal TSE
    Admin
    Lance | Principal TSE avatar
    1043 posts

    Posted 20 Aug Link to this post

    Hello Petr,

    We usually do have an event that fires when the DataGrid generates columns automatically. However, this hasn't been implemented in UWP's DataGrid yet. You could use the Columns.CollectionChanged event in a similar fashion, but I have a better idea.

    I have just realized you might be happy with just disabling IsCaseSensitive for all the TextFilterControls in the DataGrid. You can accomplish this without using a custom "MyFilterControl" or the "ColumnMarker"attached property.

    Let's edit the previous example I sent.

    Updated Example

    Step 1. Remove the columns and go back to AutoGenerateColumns=True (the default):

    <grid:RadDataGrid x:Name="DataGrid"
                                   ItemsSource="{Binding Employees}">
        <grid:RadDataGrid.Commands>
            <local:CustomFilterButtonTapCommand />
        </grid:RadDataGrid.Commands>
    </grid:RadDataGrid>

    Step 2. Delete ColumnMarker and MyFilterControl classes

    Step 3. Update the CustomFilterButtonTapCommand class to the following:

    public class CustomFilterButtonTapCommand : DataGridCommand
    {
        public CustomFilterButtonTapCommand()
        {
            this.Id = CommandId.FilterButtonTap;
        }
    
        public override bool CanExecute(object parameter)
        {
            return true;
        }
    
        public override void Execute(object parameter)
        {
            var context = parameter as FilterButtonTapContext;
    
            // If the column's 1st filter control is a TextFilterControl
            if (context.FirstFilterControl is DataGridTextFilterControl textfilterControl1)
            {
                textfilterControl1.IsCaseSensitive = false;
            }
    
            // If the column's 2nd filter control is a TextFilterControl
            if (context.SecondFilterControl is DataGridTextFilterControl textfilterControl2)
            {
                textfilterControl2.IsCaseSensitive = false;
            }
    
            this.Owner.CommandService.ExecuteDefaultCommand(CommandId.FilterButtonTap, context);
        }
    }

    I have attached an updated version of the demo so you can see this at runtime:

    Regards, Lance | Technical Support Engineer, Principal
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Petr
    Petr avatar
    5 posts
    Member since:
    Jul 2019

    Posted 20 Aug in reply to Lance | Principal TSE Link to this post

    Hi Lance,

    Your solution is excellent! Thank you very much. It works for me.



    Petr.
Back to Top