Hello,
I have a telerik grid and I am happy with functionalities of the filtering control. By the way I want to change the default value of the filtering control combo box (now is equal to) in to "Contains"?
Thanking You
I have a telerik grid and I am happy with functionalities of the filtering control. By the way I want to change the default value of the filtering control combo box (now is equal to) in to "Contains"?
Thanking You
10 Answers, 1 is accepted
0
Accepted
Hello Indika,
Here is one way to do this:
I hope this helps.
Kind regards,
Ross
the Telerik team
Here is one way to do this:
<Window x:Class="DefaultFilterOperator.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:my="clr-namespace:DefaultFilterOperator" Title="MainWindow" Height="700" Width="700"> <Window.Resources> <my:MyViewModel x:Key="MyViewModel"/> </Window.Resources> <Grid DataContext="{StaticResource MyViewModel}"> <telerik:RadGridView Grid.Row="0" Name="clubsGrid" ItemsSource="{Binding Clubs}" AutoGenerateColumns="False" Margin="5"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid></Window>using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using Telerik.Windows.Data;using Telerik.Windows.Controls;using Telerik.Windows.Controls.GridView;namespace DefaultFilterOperator{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var nameColumn = (GridViewBoundColumnBase)this.clubsGrid.Columns[0]; var customFilteringControl = new MyFilteringControl(); nameColumn.FilteringControl = customFilteringControl; } } /// <summary> /// MyFilteringControl /// </summary> public class MyFilteringControl : FilteringControl { public override void Prepare(GridViewBoundColumnBase column) { base.Prepare(column); FilteringViewModel vm = this.DataContext as FilteringViewModel; if (vm != null) { if (!vm.Filter1.IsActive) { vm.Filter1.Operator = FilterOperator.Contains; } if (!vm.Filter2.IsActive) { vm.Filter2.Operator = FilterOperator.Contains; } } } }}I hope this helps.
Kind regards,
Ross
the Telerik team
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 Public Issue Tracking
system and vote to affect the priority of the items
0
Indika
Top achievements
Rank 1
answered on 23 Aug 2010, 09:03 PM
Hello Ross,
Thanks a lot for the solution. It worked well and I have managed to reached desired functionality.
But I have another concern. My application have about 5 gridview's with having 10 columns each(approx) and also some of them will be hidden based on the business logics.
Will there be any performance issues if I loop through gridview columns as you mentioned? or is there any other approach that I can get round of this issue?
Thanking You..
Thanks a lot for the solution. It worked well and I have managed to reached desired functionality.
But I have another concern. My application have about 5 gridview's with having 10 columns each(approx) and also some of them will be hidden based on the business logics.
Will there be any performance issues if I loop through gridview columns as you mentioned? or is there any other approach that I can get round of this issue?
Thanking You..
0
Hello Indika,
I do not think that there will be any performance hit, but you can go ahead and try it.
Sincerely yours,
Ross
the Telerik team
I do not think that there will be any performance hit, but you can go ahead and try it.
Sincerely yours,
Ross
the Telerik team
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 Public Issue Tracking
system and vote to affect the priority of the items
0
Indika
Top achievements
Rank 1
answered on 24 Aug 2010, 09:09 AM
Thank you very much for your support..
0
Johannes
Top achievements
Rank 1
answered on 30 Jan 2015, 11:07 AM
I'm trying to do the same thing in version Q3 2013 because I want my users to decice the default filter option.
Unfortunately the code shown above doesn't work. When I set column.FilteringControl to a custom control inheriting from Telerik.Windows.Controls.GridView.FilteringControl like shown above, the filter popup does not open anymore.
As I said I am using Q3-2013 and the Windows 8 theme. Can you please update the sample?
Unfortunately the code shown above doesn't work. When I set column.FilteringControl to a custom control inheriting from Telerik.Windows.Controls.GridView.FilteringControl like shown above, the filter popup does not open anymore.
As I said I am using Q3-2013 and the Windows 8 theme. Can you please update the sample?
0
Hello Johannes,
I would suggest you to follow the approach from the Change the Default Selected Filter Operators help article. Please give it a try and let me know how it works for you.
Regards,
Yoan
Telerik
I would suggest you to follow the approach from the Change the Default Selected Filter Operators help article. Please give it a try and let me know how it works for you.
Regards,
Yoan
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Johannes
Top achievements
Rank 1
answered on 05 Feb 2015, 11:03 AM
Hello Yoan,
Thanks for your help, now it's working fine. However I am wondering why those DefaultFilterOperators are not implemented as Dependency Properties. So here's my extension:
The only part that's still not looking good is the "AND" or "OR" operator between DefaultOperator1 and DefaultOperator2. By default this value is "AND". Is there any way to change this default behavior too so it's possible to preselect a combination like "StartsWith" "OR" "EndsWith"?
Thanks for your help, now it's working fine. However I am wondering why those DefaultFilterOperators are not implemented as Dependency Properties. So here's my extension:
public class CustomRadGridView : RadGridView{ #region Fields // Static Fields public static readonly DependencyProperty DefaultFilterOperator1Property; public static readonly DependencyProperty DefaultFilterOperator2Property; #endregion #region Constructors static CustomRadGridView() { DefaultFilterOperator1Property = DependencyProperty.Register("DefaultFilterOperator1", typeof(FilterOperator), typeof(CustomRadGridView), new PropertyMetadata(default(FilterOperator))); DefaultFilterOperator2Property = DependencyProperty.Register("DefaultFilterOperator2", typeof(FilterOperator), typeof(CustomRadGridView), new PropertyMetadata(default(FilterOperator))); } public CustomRadGridView() { FilterOperatorsLoading += OnFilterOperatorsLoading; } #endregion #region Properties public FilterOperator DefaultFilterOperator1 { get { return (FilterOperator) GetValue(DefaultFilterOperator1Property); } set { SetValue(DefaultFilterOperator1Property, value); } } public FilterOperator DefaultFilterOperator2 { get { return (FilterOperator) GetValue(DefaultFilterOperator2Property); } set { SetValue(DefaultFilterOperator2Property, value); } } #endregion #region Events private void OnFilterOperatorsLoading(object sender, FilterOperatorsLoadingEventArgs e) { // DefaultOperator1 (Row and Popup Mode) e.DefaultOperator1 = DefaultFilterOperator1; // DefaultOperator2 (Popup Mode only) if (FilteringMode == FilteringMode.Popup) { e.DefaultOperator2 = DefaultFilterOperator2; } } #endregion}The only part that's still not looking good is the "AND" or "OR" operator between DefaultOperator1 and DefaultOperator2. By default this value is "AND". Is there any way to change this default behavior too so it's possible to preselect a combination like "StartsWith" "OR" "EndsWith"?
0
Hello Johannes,
You can change the logical operator per column like so:
I hope this helps.
Regards,
Yoan
Telerik
You can change the logical operator per column like so:
var columnFilter = gridview1.Columns["Name"].ColumnFilterDescriptor as IColumnFilterDescriptor;columnFilter.FieldFilter.LogicalOperator = FilterCompositionLogicalOperator.Or;I hope this helps.
Regards,
Yoan
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Johannes
Top achievements
Rank 1
answered on 06 Feb 2015, 09:22 AM
Hello Yoan,
Thanks for you help. I've added another Dependeny Property called "Logical Operator" of type FilterCompositionLogicalOperator so I can set the operator in XAML. Here's my updated code behind:
Sadly there is no change on my UI when setting Logical Operator to "Or" instead of default value "And". If value of property LogicalOperator is "Or" that value will be written to e.Column.ColumnFilterDescriptor.FieldFilter.LogicalOperator but as I said the UI doesn't change its ComboBox to "Or". When I close the filter popup, reopen it and debug the event e.Column.ColumnFilterDescriptor.FieldFilter.LogicalOperator shows its value is still (or maybe again) "And".
Thanks for you help. I've added another Dependeny Property called "Logical Operator" of type FilterCompositionLogicalOperator so I can set the operator in XAML. Here's my updated code behind:
private void OnFilterOperatorsLoading(object sender, FilterOperatorsLoadingEventArgs e){ // Row and Popup Mode e.DefaultOperator1 = DefaultFilterOperator1; // Popup Mode only if (FilteringMode == FilteringMode.Popup) { // LogicalOperator e.Column.ColumnFilterDescriptor.FieldFilter.LogicalOperator = LogicalOperator; // DefaultOperator2 e.DefaultOperator2 = DefaultFilterOperator2; }}Sadly there is no change on my UI when setting Logical Operator to "Or" instead of default value "And". If value of property LogicalOperator is "Or" that value will be written to e.Column.ColumnFilterDescriptor.FieldFilter.LogicalOperator but as I said the UI doesn't change its ComboBox to "Or". When I close the filter popup, reopen it and debug the event e.Column.ColumnFilterDescriptor.FieldFilter.LogicalOperator shows its value is still (or maybe again) "And".
0
Hi,
Actually the LogicalOperator cannot be changed when the FilterOperatorsLoading event is raised. It is already set by this time. Please try the following code snippet and let me know about the result:
Regards,
Yoan
Telerik
Actually the LogicalOperator cannot be changed when the FilterOperatorsLoading event is raised. It is already set by this time. Please try the following code snippet and let me know about the result:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var columnFilter = clubsGrid.Columns["Name"].ColumnFilterDescriptor as IColumnFilterDescriptor; columnFilter.FieldFilter.LogicalOperator = FilterCompositionLogicalOperator.Or; }Regards,
Yoan
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.