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

[Solved] Force the funnel icon of filtering control to light up

17 Answers 203 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Adi
Top achievements
Rank 1
Adi asked on 29 Sep 2010, 01:28 PM
Hi All,

I was wondering if it is possible to force the funnel icon of filter to turn on? I tried setting the IsActive property but that doesn't seem to update/reflect in the UI?

-Adi

17 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 29 Sep 2010, 01:37 PM
Hi Adi,

What is the reason for which you want to do a thing like that?

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
Adi
Top achievements
Rank 1
answered on 29 Sep 2010, 01:51 PM
I have a custom radgridview, on the rowload event of which, based on the datatype of the source the column is binding to, I create a customfilter. For eg, if the source is of type datetime, I attach a custom filter control having two date pickers and submit/cancel button. Now the custom filter does work fine, however the filtering does not have any effect on the funnel icon even though I set its isActive property. you can check the below code to get a feel of it.


xaml of my custom filter:

  <Border x:Name="LayoutRoot" Style="{StaticResource ThickBorderStyle}" >
        <Grid Style="{StaticResource GenericLayoutGridStyle}" Background="AliceBlue" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="120"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>                
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Grid.Column="0" Grid.Row="0" Margin="2"  Text="From Date:" Style="{StaticResource GenericLabelStyle}"/>
            <TextBlock Grid.Column="1" Grid.Row="0" Margin="2"  Text="To Date:" Style="{StaticResource GenericLabelStyle}"/>
            <controls:PmcDatePicker x:Name="fromDatePicker" Grid.Column="0" Grid.Row="1" Margin="2" />
            <controls:PmcDatePicker x:Name="toDatePicker" Grid.Column="1" Grid.Row="1" Margin="2" />
            <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Style="{StaticResource GenericPanelStyle}">
                <telerik:RadButton x:Name="filterButton" Content="Filter" Click="OnFilter" Margin="2" Width="80" Style="{StaticResource GenericButtonStyle}"/>
                <telerik:RadButton x:Name="clearButton" Content="Clear" Click="OnClear" Margin="2" Width="80" Style="{StaticResource GenericButtonStyle}"/>                
            </StackPanel>
        </Grid>
    </Border>

Code behind of my custom filter:

   public partial class FromToDateFilter : UserControl, IFilteringControl
    {

        private GridViewBoundColumnBase column;
        private CompositeFilterDescriptor CompositeFilter;
        private Telerik.Windows.Data.FilterDescriptor fromFilter;
        private Telerik.Windows.Data.FilterDescriptor toFilter;

        public PmcFromToDateFilter()
        {
            InitializeComponent();
        }

        public bool IsActive
        {
            get
            {

                return (bool)GetValue(IsActiveProperty);
            }
            set
            {
               
                SetValue(IsActiveProperty, value);
            }
        }

        public static readonly DependencyProperty IsActiveProperty =
            DependencyProperty.Register(
            "IsActive", typeof(bool), typeof(PmcFromToDateFilter), new PropertyMetadata(false));

        public void Prepare(GridViewBoundColumnBase column)
        {
            this.column = column;
            if (this.CompositeFilter == null)
            {
                this.CreateFilters();
            }
            this.fromFilter.Value = this.FromDate;
            this.toFilter.Value = this.ToDate;
        }

        private void CreateFilters()
        {
            string dataMember = this.column.DataMemberBinding.Path.Path;
            this.CompositeFilter = new CompositeFilterDescriptor();
            this.fromFilter = new Telerik.Windows.Data.FilterDescriptor(dataMember, Telerik.Windows.Data.FilterOperator.IsGreaterThanOrEqualTo, null);
            this.CompositeFilter.FilterDescriptors.Add(this.fromFilter);
            this.toFilter = new Telerik.Windows.Data.FilterDescriptor(dataMember, Telerik.Windows.Data.FilterOperator.IsLessThanOrEqualTo, null);
            this.CompositeFilter.FilterDescriptors.Add(this.toFilter);
           

        }

        public DateTime? FromDate
        {
            get
            {
                return this.fromDatePicker.SelectedDate.GetValueOrDefault(DateTime.MinValue);
            }
            set
            {
                this.fromDatePicker.SelectedDate = value;
            }
        }

        public DateTime? ToDate
        {
            get
            {
                DateTime newDateTime;
                if (this.toDatePicker.SelectedDate.HasValue)
                {
                    newDateTime = new DateTime(this.toDatePicker.SelectedDate.Value.Year, this.toDatePicker.SelectedDate.Value.Month, this.toDatePicker.SelectedDate.Value.Day,
                                                             23, 59, 59);
                }
                else
                {
                    newDateTime = this.toDatePicker.SelectedDate.GetValueOrDefault(DateTime.MaxValue);
                }
                return newDateTime;
            }
            set
            {
                this.toDatePicker.SelectedDate = value;
            }

        }

        public PmcDatePicker FromPicker
        {
            get { return this.fromDatePicker; }
        }

        public PmcDatePicker ToPicker
        {
            get { return this.toDatePicker; }
        }

        private void OnFilter(Object sender, RoutedEventArgs e)
        {
            this.fromFilter.Value = this.FromDate;
            this.toFilter.Value = this.ToDate;
            if (!this.column.DataControl.FilterDescriptors.Contains(this.CompositeFilter))
            {
                this.column.DataControl.FilterDescriptors.Add(this.CompositeFilter);
            }
            this.IsActive = true;
        }

        private void OnClear(Object sender, RoutedEventArgs e)
        {
            if (this.column.DataControl.FilterDescriptors.Contains(this.CompositeFilter))
            {
                this.column.DataControl.FilterDescriptors.Remove(this.CompositeFilter);
            }
            this.FromDate = null;
            this.ToDate = null;
            this.fromDatePicker.DateTimeText = null;
            this.toDatePicker.DateTimeText = null;
            this.IsActive = false;
        }
    }
}


This is how I attach it in the rowload event of the gridview 

void GridView_RowLoaded(object sender, RowLoadedEventArgs e)
        {
            
           
            foreach (var c in e.Row.Cells)
            {

                if (c.DataColumn != null)
                    if (c.DataColumn.DataType == typeof(DateTime?) || c.DataColumn.DataType == typeof(DateTime))
                    {
                        if (c.DataColumn.FilteringControl != null)
                        {
                            if (c.DataColumn.FilteringControl.GetType() != typeof(FromToDateFilter))
                            {
                                c.DataColumn.FilteringControl = new FromToDateFilter();                    

                            }

                        }
                        else
                        {
                            c.DataColumn.FilteringControl = new FromToDateFilter();
                        }
                    }
            }
        }


let me know if I am missing something.

Thanks,
Adi
0
Rossen Hristov
Telerik team
answered on 29 Sep 2010, 02:13 PM
Hi Adi,

Please, open a separate support ticket and send me a running sample project. It will be easier for me to debug it if I have a running sample project. Thanks in advance.

P.S. I suppose that you have developed this by following my blog post.

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
Adi
Top achievements
Rank 1
answered on 29 Sep 2010, 02:24 PM
Ross,

Yes!! Thanks for the wonderful blogpost!

 Do I need to send you a project? Its basically the same stuff you have done with the only exception that you know at compile time that you are going to apply Datetime filter to the column having datetime values and put the following code in  xaml 

<telerikGrid:GridViewDataColumn.FilteringControl>
  <controls: FromToDateFilter/>
</telerikGrid:GridViewDataColumn.FilteringControl>

The funnel icon works for me if I do it this way. However, to avoid redundancy, I need to add a filter in the rowload event of the radgrid if the type is datetime. And here where the problem with funnel icon seems to occur. 

Are you able to add a custom filter in the rowload event of the radgridview and still the funnel icon works?

Thanks again,
Adi
0
Rossen Hristov
Telerik team
answered on 29 Sep 2010, 02:33 PM
Hello Adi,

Oh, do not do it in the RowLoaded event. This will be fired thousands of times for every single row. There is no sense to do this at all. There is one filtering control per one column. It does not matter how many rows there are!

That's it.

You can assign it either in XAML or in the AutoGeneratingColumn event handler.

Bottomline is: Set the FilteringControl only once -- not thousands of times.

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
Adi
Top achievements
Rank 1
answered on 29 Sep 2010, 02:46 PM
Hey Ross,

I do check if the filtering control is already present and if its present I do not assign it again. This way I am able to attach just one filter per column. 



                if (c.DataColumn != null)
                    if (c.DataColumn.DataType == typeof(DateTime?) || c.DataColumn.DataType == typeof(DateTime))
                    {
                        if (c.DataColumn.FilteringControl != null)
                        {
                            if (c.DataColumn.FilteringControl.GetType() != typeof(FromToDateFilter))
                            {
                                c.DataColumn.FilteringControl = new FromToDateFilter();                    

                            }

                        }
                        else
                        {
                            c.DataColumn.FilteringControl = new FromToDateFilter();
                        }
                    }
           

Thanks,
Adi
0
Rossen Hristov
Telerik team
answered on 29 Sep 2010, 03:09 PM
Hello Adi,

Well, since the sample project from the blog post works correctly and your one does not, it is clear that something has to be different between the two.

Unless I have something to debug I can do little to help you. Thank you for your understanding.

All the best,
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
Adi
Top achievements
Rank 1
answered on 29 Sep 2010, 03:23 PM
 I will send you the project if I don't get around this issue. BTW the filter is working fine but the funnel is the only problem out here.

I just wanted you to verify if one adds a filter in the rowload event (obviously checking if the filtering control doesn't already exist to avoid assigning multiple filters to the same column) does the funnel seem to work fine? I believe thats not the way you have implemented your sample project, in which you just attach the filtering control in the xaml for a particular column before hand. 

Thanks,
Aadit
0
Rossen Hristov
Telerik team
answered on 29 Sep 2010, 03:27 PM
Hello Adi,

Probably this is causing the problem. Anyway, you really should not be doing this in this event handler. It is plain wrong. No matter that you do have a check. It is just wrong. The action that you need to do can be done even if the grid has not ItemsSource set. It does not have to depend in any way on rows being loaded.

Please, just do it either in XAML or in the code-behind after InitializeComponent if you have manually defined columns, or in the AutoGeneratingColumn event if you do not.

Tell me, why do you insist in doing this thing in the worst possible place available???

Best wishes,
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
Adi
Top achievements
Rank 1
answered on 30 Sep 2010, 03:09 PM
Hi Ross,
Doing it in the xaml is totally not an option for me as it would mean a change to lot of files through out the application and lot of redundancy as well.

I tried using the AutoGeneratingColumn event, however I couldn't figure out a way to determine the column's datatype. Would you know how can I achieve this??

I didn't want to do it in the RowLoaded event, but that seem to be the best possible location where I could decipher what the column's datatype would be in the following manner....hence! 

    foreach (var c in e.Row.Cells)
            {

                if (c.DataColumn != null)
                    if (c.DataColumn.DataType == typeof(DateTime?) || c.DataColumn.DataType == typeof(DateTime))
                    {

Is there any other location where I can get to know this??

Thanks for all the help,

sincerely,
Adi
0
Rossen Hristov
Telerik team
answered on 04 Oct 2010, 08:58 AM
Hi Adi,

The data type of the column could be found like this:

private void clubsGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
    var boundColumn = e.Column as GridViewBoundColumnBase;
    if (boundColumn != null)
    {
        var propertyName = boundColumn.DataMemberBinding.Path.Path;
        var propertyType = boundColumn.DataType;
        Debug.WriteLine(string.Format("{0} is of type {1}", propertyName, propertyType));
    }
}

I have attached a sample project.

I hope this helps.

Best wishes,
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
Adi
Top achievements
Rank 1
answered on 12 Oct 2010, 06:03 PM
Thanks Ross, but what if the AutoGeneratingColumn is set to false in the xaml (As I don't want to display all the columns but display them selectively). How would I achieve both?

-Adi
0
Rossen Hristov
Telerik team
answered on 13 Oct 2010, 08:37 AM
Hello Adi,

Well, then it is you who are creating the columns, isn't it. Since it is you that are creating the columns -- you know everything that you need, i.e. types, property names, etc.

There are only two options in the entire world -- columns are auto-generated (we covered this one) and columns are created by the developer by hand.

When you create your columns in code-behind by hand (like you say you will) -- assign your FilteringControl to it. It is that simple.

I really hope this makes sense now.

Greetings,
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
Adi
Top achievements
Rank 1
answered on 13 Oct 2010, 01:27 PM
For a simple reason! when you already have 200+ columns in a large scale data driven application it becomes quite difficult to go over every column assigning the filtering control!! And to add to it, from the design standpoint I don't think it is a good idea to repeat the same lines of code.

Hope you see through my justification,

Thanks,
Adi
0
Rossen Hristov
Telerik team
answered on 13 Oct 2010, 02:25 PM
Hi Adi,

You can use the foreach statement and go around those 200 columns. Inside the foreach you can check the specific column (i.e. its name, its type, whatever matters for your choice of FilteringControl) and choose what FilteringControl to assign to it. Does this make sense? In this way you will not repeat the same lines of code 200+ times. They will be repeated only 1 time.

I hope this helps.

Greetings,
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
Adi
Top achievements
Rank 1
answered on 13 Oct 2010, 04:03 PM
Of course I get that, However my point is

To summarize, I have two options now:

1. Use AutoGeneratingColumn Event and use foreach to assign the filtering control based on the datatype ->
              
            I am not able to go for the above option, because for my radgridview I have set the AutoGenerateColumn event to false because I initially show selective few columns to the users. Users can then select other columns to be displayed if they want to, by checking them on. If I set AutoGenerateColumn = true, it shows all the columns instead of selective few which were to be initially displayed.

2. Assign the filtering control in Xaml ->
   
            I have too many columns to go for this option.

Am I missing something?

-Adi
0
Vlad
Telerik team
answered on 15 Oct 2010, 11:37 AM
Hello ,

When you set AutoGenerateColumns property to true (default value) you can use AutoGeneratingColumn event to:

1. Cancel auto-generating of a column
2. Replace auto-generated column with new column instance
3. Set various column properties. 

Greetings,
Vlad
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
Tags
GridView
Asked by
Adi
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Adi
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or