This is a migrated thread and some comments may be shown as answers.

RadDataGrid set case-sensetice mode of to all columns

4 Answers 33 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Petr
Top achievements
Rank 1
Petr asked on 19 Aug 2019, 01:59 PM
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

4 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 19 Aug 2019, 07:09 PM

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
0
Petr
Top achievements
Rank 1
answered on 20 Aug 2019, 01:38 PM
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


0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 20 Aug 2019, 03:00 PM

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
0
Petr
Top achievements
Rank 1
answered on 20 Aug 2019, 03:38 PM
Hi Lance,

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



Petr.
Tags
DataGrid
Asked by
Petr
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Petr
Top achievements
Rank 1
Share this question
or