Create a Custom Field Filter Editor

13 posts, 0 answers
  1. Ghasem
    Ghasem avatar
    15 posts
    Member since:
    May 2014

    Posted 15 May 2014 Link to this post

    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.
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 May 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ghasem
    Ghasem avatar
    15 posts
    Member since:
    May 2014

    Posted 15 May 2014 Link to this post

    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.
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 May 2014 Link to this post

    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.
     
  6. Ghasem
    Ghasem avatar
    15 posts
    Member since:
    May 2014

    Posted 16 May 2014 Link to this post

    please give me a sample code. thank you.
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 May 2014 Link to this post

    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.
     
  8. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 07 Jan Link to this post

    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.

  9. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 08 Jan in reply to skrec Link to this post

    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?

  10. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 11 Jan Link to this post

    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
  11. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 12 Jan in reply to Dilyan Traykov Link to this post

    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.    }

  12. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 14 Jan Link to this post

    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
  13. skrec
    skrec avatar
    10 posts
    Member since:
    Mar 2011

    Posted 14 Jan in reply to Dilyan Traykov Link to this post

    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

  14. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 18 Jan Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready