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

How far can i customize the default filter?

5 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vitor
Top achievements
Rank 1
Vitor asked on 05 Apr 2016, 08:21 AM

    Hey Telerik!

 

So, for now I just need two custom features for the filter control (filter row mode):

- first is a bit complex: I need to deferred filter at the very moment the user first clicks on the funnel filter icon. The second times he clicks it, it should display the default filter popup. So basically: user types on filter, nothing happens -> user clicks on the icon, it filters -> user click it once more, opens the popup

- now second is: I need to reduce the amount of information from inside that popup for a more friendly GUI of it

 

if you have an answer for either of those, please let me know asap, as my trial period is about to end!

 

Thank you, I am really enjoying telerik support so far!

5 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 05 Apr 2016, 09:39 AM
Hi Vitor,

Let me go straight to your questions:

1. I am afraid that this is not supported out-of-the-box. The closest solution for this is to Change the Default Selected Filter Operator. In this way when you click the funnel it will filter using the new filter operator. 
2. I have already answered the other forum thread. However, if you are usng FilterMode=FilterRow then you need to Remove Some of the Available Filter Operators. In this way you will limit the items displayed in the popup.

Regards,
Yoan
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Vitor
Top achievements
Rank 1
answered on 05 Apr 2016, 11:35 AM

thank you for your answer, Yoan.

Regarding the solution for the second point, is it possible to have a central style so that every grid will use it by default?

so that I won't keep repeating that code all the time

thank you!

0
Yoan
Telerik team
answered on 05 Apr 2016, 11:54 AM
Hi Vitor,

The way to go is with an Attached behavior. You will write the attached behavior only once. This attached behavior will attach to the event and will remove the operators. Here is a very nice article about event handling with attached behaviors.

Regards,
Yoan
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Vitor
Top achievements
Rank 1
answered on 05 Apr 2016, 01:14 PM

Hi Yoan

 

that approach is brilliant. but I do not see why my breakpoints inside that behavior class wont even hit

please help!

here is some code:

XAML:

<telerik:RadGridView Name="RadGridView"  ItemsSource="{Binding View}" IsReadOnly="True" Style="{StaticResource VitorStyle}"  AutoGenerateColumns="False" MouseMove="RadGridView_MouseMove">

Dictionary (resource file):

                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                xmlns:my="clr-namespace:HierarchyIsExpandable"
                xmlns:u="clr-namespace:TelerikVirtualization.Utils"
                xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" >
    <Style x:Key="VitorStyle" TargetType="telerik:RadGridView" >
         
        <Setter Property="AutoGenerateColumns" Value="False"></Setter>
        <Setter Property="FilteringMode" Value="FilterRow"></Setter>
        <Setter Property="ControlPanelItems">
            <Setter.Value>
                <telerik:ControlPanelItemCollection>
                    <telerik:ControlPanelItem ButtonTooltip="Column chooser" >
                        <telerik:ControlPanelItem.ContentTemplate>
                            <DataTemplate>
                                <ListBox ItemsSource="{Binding Columns}"  BorderThickness="0">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <CheckBox Content="{Binding Header, Mode=OneWay}"
                                                  IsChecked="{Binding IsVisible, Mode=TwoWay}" />
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </DataTemplate>
                        </telerik:ControlPanelItem.ContentTemplate>
                    </telerik:ControlPanelItem>
                </telerik:ControlPanelItemCollection>
            </Setter.Value>
        </Setter>
  
  
    </Style>
    <Style TargetType="telerik:RadGridView">
        <Setter Property="u:GridFilterBehavior.IsEnabled" Value="true" />
    </Style>
</ResourceDictionary>

Behavior class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
 
namespace TelerikVirtualization.Utils
{
    public class GridFilterBehavior : DependencyObject
    {
        public static readonly DependencyProperty IsEnabledProperty;
 
        static GridFilterBehavior()
        {
            IsEnabledProperty = DependencyProperty.RegisterAttached(
                "IsEnabled", //Name of the property
                typeof(bool),//Type of the attached property
                typeof(GridFilterBehavior),//Type of the class that provides the property
                new FrameworkPropertyMetadata(false, OnBehaviorEnabled)); //Default value
        }
 
        public bool IsEnabled
        {
            get { return (bool)this.GetValue(IsEnabledProperty); }
            set { SetValue(IsEnabledProperty, value); }
        }
        public static void OnBehaviorEnabled(
    DependencyObject dependencyObject,
    DependencyPropertyChangedEventArgs args)
        {
            RadGridView gridview = (RadGridView)dependencyObject;
 
            gridview.FilterOperatorsLoading += (s, e) =>
            {
                if (e.Column.UniqueName == "Name")
                {
                    e.AvailableOperators.Remove(FilterOperator.IsEqualTo);
                    e.AvailableOperators.Remove(FilterOperator.IsNotEqualTo);
 
                    e.AvailableOperators.Remove(FilterOperator.IsGreaterThanOrEqualTo);
                    e.AvailableOperators.Remove(FilterOperator.IsLessThanOrEqualTo);
 
                    e.AvailableOperators.Remove(FilterOperator.IsNull);
                    e.AvailableOperators.Remove(FilterOperator.Contains);
 
                    e.DefaultOperator1 = FilterOperator.IsGreaterThan;
                    e.DefaultOperator2 = FilterOperator.IsLessThan;
                }
            };
        }
    }
}

 

thank you

 

 

 

0
Accepted
Yoan
Telerik team
answered on 08 Apr 2016, 12:17 PM
Hello Vitor,

I am sending you a sample project which demonstrates the suggested approach. Please review it and let me know how it works at your end.

Regards,
Yoan
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Vitor
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Vitor
Top achievements
Rank 1
Share this question
or