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

Create a Custom Field Filter Editor

12 Answers 223 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ghasem
Top achievements
Rank 1
Ghasem asked on 15 May 2014, 09:00 AM
Hi
I am using Telerik version Q3 2013. I want to use my custom control instead of RadDateTimePicker control according to this post in row filter mode in Gridview. My Gridview columns are dynamic. Please provide with the source code so that I can apply this change as I want.

12 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 15 May 2014, 10:11 AM
Hi,

The other approach would be to modify the existing editor as explained in the Customize the Default Field Filter Editor article. How does this work for you?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ghasem
Top achievements
Rank 1
answered on 15 May 2014, 10:20 AM
Thank you for reply but my problem is that i want to replace it by my own User Control as explained in this post.
Please help me with a sample project.
0
Dimitrina
Telerik team
answered on 16 May 2014, 08:51 AM
Hi,

The e.Editor is a ReadOnly property and it cannot be replaced when the FieldFilterEditorCreated is raised. I am afraid you will have to override the CreateFieldFilterEditor method creating a custom column.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ghasem
Top achievements
Rank 1
answered on 16 May 2014, 04:18 PM
please give me a sample code. thank you.
0
Dimitrina
Telerik team
answered on 19 May 2014, 02:12 PM
Hello,

The code I can suggest is the one from the Create a Custom Field Filter Editor article. You should create a custom column and override the CreateFieldFilterEditor method. 

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
skrec
Top achievements
Rank 1
answered on 07 Jan 2016, 08:25 AM

Hi

I have created custom column with overriden CreateFieldFilterEditor method.

 

01.public class SalusGridViewAgendaItemDataColumn : GridViewDataColumn
02.   {
03.       public override FrameworkElement CreateFieldFilterEditor()
04.       {
05.           var filterControl = new SalusAgendaItemTypeFilterControl();
06. 
07.           // This binding will transfer the significant property of your editor to the filtering view model.
08.           Binding selectedValueBinding = new Binding("Value");
09.           selectedValueBinding.Mode = BindingMode.TwoWay;
10.           selectedValueBinding.FallbackValue = null;
11.           selectedValueBinding.Converter = new AgendaItemTypeFilterEditorConverter();
12. 
13.           var dc = DataContext;
14.           filterControl.SetBinding(SalusAgendaItemTypeFilterControl.SelectedAgendaItemTypeProperty, selectedValueBinding);
15.            
16.           return filterControl;
17.       }
18.   }

 

But the suggested binding fails, because viewmodel does not contains property Value. DataContext of custom SalusGridViewAgendaItemDataColumn is my custom viewmodel (viewmodel of whole gridview) not yours viewmodel as described in documentation.

 Any suggestions? Thanks Petr.

0
skrec
Top achievements
Rank 1
answered on 08 Jan 2016, 02:55 PM

I answer myself. 

My problem is soled by using custom filtering conrol instead of defining custom column type.

 

<telerik:GridViewDataColumn.FilteringControl>
    <agenda:SalusAgendaItemTypeFilteringControl/>
</telerik:GridViewDataColumn.FilteringControl>

But why binding not works when using custom grid view data column?

0
Dilyan Traykov
Telerik team
answered on 11 Jan 2016, 03:21 PM
Hello Petr,

Can you provide the code of your SalusAgendaItemTypeFilterControl as well as the AgendaItemTypeFilterEditorConverter so that we can examine it and give you a possible explanation why the binding is not working? Otherwise, it would just be guessing.

Regards,
Dilyan Traykov
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
skrec
Top achievements
Rank 1
answered on 12 Jan 2016, 03:06 PM

Hi, thanks for reply.

 

01.<UserControl x:Class="Prodware.Salus.Client.Modules.AgendaModule.Controls.SalusAgendaItemTypeFilteringControl"
02.                           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
03.                           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
04.                           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
05.                           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"                          
06.                           mc:Ignorable="d">
07.    <Grid x:Name="RootLayout">       
08.        <ListBox Margin="5" Grid.Column="0" Grid.Row="1"
09.                 ItemsSource="{Binding AgendaItemTypes}" SelectedItem="{Binding SelectedAgendaItemType}"/>
10.    </Grid>
11.<UserControl>

 

01.public partial class SalusAgendaItemTypeFilteringControl : SalusUserControl, IFilteringControl
02.    {
03.        private GridViewDataControl _parentGrid;
04. 
05.        public SalusAgendaItemTypeFilteringControl()
06.        {
07.            InitializeComponent();
08. 
09.            RootLayout.DataContext = this;
10. 
11.            AgendaItemTypes = Enum.GetValues(typeof (AgendaActivityType)).Cast<AgendaActivityType>();
12.        }
13. 
14.        public void Prepare(GridViewColumn columnToPrepare)
15.        {
16.            _parentGrid = columnToPrepare.DataControl;
17.        }
18. 
19.        public bool IsActive { get; set; }
20. 
21.        public static readonly DependencyProperty AgendaItemTypesProperty = DependencyProperty.Register(
22.            "AgendaItemTypes", typeof(IEnumerable<AgendaActivityType>), typeof(SalusAgendaItemTypeFilteringControl), new FrameworkPropertyMetadata(default(IEnumerable<AgendaActivityType>)));
23. 
24.        public IEnumerable<AgendaActivityType> AgendaItemTypes
25.        {
26.            get { return (IEnumerable<AgendaActivityType>)GetValue(AgendaItemTypesProperty); }
27.            set { SetValue(AgendaItemTypesProperty, value); }
28.        }
29. 
30.        public static readonly DependencyProperty SelectedAgendaItemTypeProperty = DependencyProperty.Register(
31.            "SelectedAgendaItemType", typeof (AgendaActivityType), typeof (SalusAgendaItemTypeFilteringControl), new FrameworkPropertyMetadata(default(AgendaActivityType)));
32. 
33.        public AgendaActivityType SelectedAgendaItemType
34.        {
35.            get { return (AgendaActivityType) GetValue(SelectedAgendaItemTypeProperty); }
36.            set { SetValue(SelectedAgendaItemTypeProperty, value); }
37.        }
38.    }

 

01.public class AgendaItemTypeFilterEditorConverter : IValueConverter
02.    {
03.        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
04.        {
05.            if (Object.Equals(value, Telerik.Windows.Data.FilterDescriptor.UnsetValue))
06.            {
07.                // When the filter is turned off this is what your editor will get.
08.                return null;
09.            }
10. 
11.            return value;
12.        }
13. 
14.        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
15.        {
16.            if (value == null)
17.            {
18.                // When your editor want to turn off the filter this is what it should return.
19.                return Telerik.Windows.Data.FilterDescriptor.UnsetValue;
20.            }
21. 
22.            return value;
23.        }
24.    }

0
Dilyan Traykov
Telerik team
answered on 14 Jan 2016, 11:19 AM
Hello Petr,

Can you please have a look at the attached project and let me know if it produces the desired behaviour?

All I've changed is the FallbackValue of the binding for the custom column. I've switched that from null to AgendaActivityType.FreeTime. You can either remove it as a whole or provide a valid value from your AgendaActivityType enumeration.

Regards,
Dilyan Traykov
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
skrec
Top achievements
Rank 1
answered on 14 Jan 2016, 04:03 PM

Thanks for reply. Yes this works. But defining custom column with filtering control not solves my problem because I want to display fully customizable filtering control. My custom filter control is wrapped in telerik filtering control.

I have decided to use another way how to define fully customizable filtering control but still with no luck.

 See: Custom filtering control binding issue

0
Dilyan Traykov
Telerik team
answered on 18 Jan 2016, 11:25 AM
Hello Petr,

I've provided an answer to your other thread. Please take a look.

Regards,
Dilyan Traykov
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
Tags
GridView
Asked by
Ghasem
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Ghasem
Top achievements
Rank 1
skrec
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or