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

Change GridView Column filter

3 Answers 194 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yu
Top achievements
Rank 1
Yu asked on 27 Nov 2012, 02:30 PM

Hi, I use the following code to overwrite the FilteringControl

public class ContainsFilteringControl: FilteringControl
    {
        public override void Prepare(GridViewColumn gridViewColumn)
        {
            base.Prepare(gridViewColumn);
  
            var vm = DataContext as FilteringViewModel;
  
            if (vm == null) return;
              
            if (!vm.Filter1.IsActive)
            {
                vm.Filter1.Operator = FilterOperator.Contains;
            }
  
            if (!vm.Filter2.IsActive)
            {
                vm.Filter2.Operator = FilterOperator.Contains;
            }
        }
  
    }

Then, in the code behind of the view,

public MyWindow(MyViewModel viewModel)
{
      DataContext = viewModel;
      this.radGrid.Columns[2].FilteringControl = new ContainsFilteringControl();
 }

After recompile and run the application, the filter changes to Contains.

However, when the filter is opened first time, the text boxes below the filter dropdowns are not shown.

When the filter window is opended the second time, the text boxes will appear.

Anything I can do to fix this?

Thanks

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 27 Nov 2012, 02:43 PM
Hi,

This is the proper way to set default filter operators. The method that you are using is very old.

As for the disappearing textboxes -- we have never seen this behavior before. Can you send us a project that demonstrates it?

Greetings,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Yu
Top achievements
Rank 1
answered on 27 Nov 2012, 04:03 PM
Thanks. the new way works very well.

As we would like to change the default filter for all the columns which has the type of data binding of String, Is there a way to use the

FilterOperatorsLoadingEventArgs.Column property to decide what type of data is binding to the column?

Then we do not need to write lots of if statments to change the filters to every column.
0
Rossen Hristov
Telerik team
answered on 27 Nov 2012, 04:19 PM
Hi,

The Column should have a DataType property.

Greetings,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Yu
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Yu
Top achievements
Rank 1
Share this question
or