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

set default setting for filter

19 Answers 301 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Naseem
Top achievements
Rank 1
Naseem asked on 07 Jul 2011, 06:07 AM
Hi,

I would like to set a default setting on filter panel. When ever filter opens automatically it set to 'Contain' instead of 'equal to' . I've found this post related to that.

http://www.telerik.com/community/forums/silverlight/gridview/setting-a-default-value-for-the-filter.aspx

I'm using the bellow code for that purpose. However it's just working on the first click . The first time it shows 'Contain' but the next times it's still 'equal to'

ColumnFilterDescriptor numberColumnFilter = new ColumnFilterDescriptor((IDataFieldDescriptor)GridView.Columns[0]);
numberColumnFilter.FieldFilter.Filter1.Operator = FilterOperator.Contains;
GridView.FilterDescriptors.Add(numberColumnFilter);

Please guide me what I'm doing wrong.

Many thanks,
Naseem

19 Answers, 1 is accepted

Sort by
0
Naseem
Top achievements
Rank 1
answered on 07 Jul 2011, 06:38 AM
I've realized I need to put that piece of code in "FieldFilterEditorCreated" event.
However I'm not sure whether there is any better solution or not ! 

Thank you,
Naseem
0
Accepted
Dimitrina
Telerik team
answered on 07 Jul 2011, 12:32 PM
Hi Naseem,

 Actually you will need to ovveride the Prepare method of the Filtering Control like it is shown in this forum post. There is a sample project posted by Ross that is doing exactly what you would like to achieve.
You may as well review  this forum post.

Best wishes,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Naseem
Top achievements
Rank 1
answered on 08 Jul 2011, 01:09 AM
Hi Didie,
 
Thank you the quick response. I'll do based on the post you have sent me , however I need to set the filter to be 'contain' in case type of column is String . otherwise if type of column is 'int', the filter still shoud be 'Equal to'. I was wondering how I can retrieve type of column or type of the source it has been binded to?

Many Thanks,

Kind Regards,
Naseem
0
Accepted
Dimitrina
Telerik team
answered on 11 Jul 2011, 12:45 PM
Hi Naseem,

Have you changed the filtering control already?

You may get the type of the data bound to the column using the DataType property of the GridViewColumn, like so:

(gridView.Columns[1] as Telerik.Windows.Controls.GridViewBoundColumnBase).DataType

Does this help? 

Regards,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Naseem
Top achievements
Rank 1
answered on 12 Jul 2011, 01:41 AM
Hi Didie ,

Thank you so much. Now it's working fine , just the only issue is the theme of Filtering control which is silver by default. I was wondering how I can change it to be OfficeBlue theme.

var nameColumn = (GridViewBoundColumnBase)this.dgrdProduct.Columns[count];
var customFilteringControl = new MyFilteringControl();
nameColumn.FilteringControl = customFilteringControl;

public class MyFilteringControl : FilteringControl
  {
      public override void Prepare(GridViewBoundColumnBase column)
      {
          base.Prepare(column);
          var vm = this.DataContext as FilteringViewModel;
            
          if (vm != null)
          {
              if (!vm.Filter1.IsActive)
              {
                  if (column.DataType.ToString().Contains("System.Int32"))
                  {
                      vm.Filter1.Operator = FilterOperator.IsEqualTo;
                  }
                  else
                  {
                      vm.Filter1.Operator = FilterOperator.Contains;
                  }
              }
              if (!vm.Filter2.IsActive)
              {
                  if (column.DataType.ToString().Contains("System.Int32"))
                  {
                      vm.Filter2.Operator = FilterOperator.IsEqualTo;
                  }
                  else
                  {
                      vm.Filter2.Operator = FilterOperator.Contains;
                  }
              }
          }
      }

Many Thanks,
I appreciate your help,

Kind Regards,
Naseem


 
0
Accepted
Dimitrina
Telerik team
answered on 12 Jul 2011, 02:59 PM
Hello Naseem,

I am glad to hear that you have your scenario working fine.

Regarding changing the theme of the Filtering control, you may review this help article about setting a theme? There is a detailed explanation on how to change the theme of a single control.

Best wishes,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Naseem
Top achievements
Rank 1
answered on 13 Jul 2011, 12:58 AM
Thank you so much Didie for all your help :)
0
Naseem
Top achievements
Rank 1
answered on 13 Jul 2011, 02:25 AM
Hello Didie,

I have just realized there is an issue in my filtering control. I have implemented it based on the post you have sent me

http://www.telerik.com/community/forums/wpf/gridview/hide-and-filtering-options.aspx

for (int count = 0; count < dgrdProduct.Columns.Count; ++count)
           {
               var nameColumn = (GridViewBoundColumnBase)this.dgrdProduct.Columns[count];
               var customFilteringControl = new CustomFilteringControl();
               nameColumn.FilteringControl = customFilteringControl;
           }

I set the above code after GridView.ItemSource being set.It's working fine ,except on the first click . The first time ,it comes as 1.jpg and on the second click and then  it's similar to 2.jpg.

I don't know why it's like that !
Would you please guide me what I'm doing wrong,

Many thanks,
Naseem
0
Dimitrina
Telerik team
answered on 15 Jul 2011, 10:39 AM
Hello Naseem,

 I am a little bit confused. May you please clarify if I have understood you right:
1. The 1.jpg is wrong
2. The 2.jpg is right
3. You have followed the example posted by Ross in the specified forum thread.
4.Are you hiding the Text Boxes (as I have understood that you would like to change the filter operators)?

May you please paste the related code of your CustomFilteringControl?

Best wishes,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Naseem
Top achievements
Rank 1
answered on 18 Jul 2011, 02:09 AM
Hi Didie,

Sorry if my request wasn't clear enough . Here is the scenario:

1. I'd like to change the filter control based on the column data type .
2. if the type is string , the filtercontrol.filter1 dropdown list shows "Contain"
3. if the type is int, the filtercontrol.filter1 dropdown list shows "Equal to"

I have done that by using bellow approach

http://www.telerik.com/community/forums/silverlight/gridview/setting-a-default-value-for-the-filter.aspx


for (int count = 0; count < dgrdProduct.Columns.Count; ++count)
            {
                var nameColumn = (GridViewBoundColumnBase)this.dgrdProduct.Columns[count];
                var customFilteringControl = new CustomFilteringControl();
                nameColumn.FilteringControl = customFilteringControl;
  
            }

public class CustomFilteringControl : FilteringControl
    {
        public override void Prepare(GridViewBoundColumnBase column)
        {
            base.Prepare(column);
  
            Telerik.Windows.Controls.StyleManager.SetTheme(this, new Office_BlueTheme());
  
            var vm = this.DataContext as FilteringViewModel;
  
            if (vm != null)
            {
                if (!vm.Filter1.IsActive)
                {
                    if (column.DataType.ToString().Contains("System.Int"))
                    {
                        vm.Filter1.Operator = FilterOperator.IsEqualTo;
                    }
                    else
                    {
                        vm.Filter1.Operator = FilterOperator.Contains;
                    }
                }
  
                if (!vm.Filter2.IsActive)
                {
                    if (column.DataType.ToString().Contains("System.Int"))
                    {
                        vm.Filter2.Operator = FilterOperator.IsEqualTo;
                    }
                    else
                    {
                        vm.Filter2.Operator = FilterOperator.Contains;
                    }
                }
            }
        }

Here is the issue:
1.on the First Click (click on Filtering) it shows 1.jpg (which is wrong since it doesn't have the filtering text boxes)
2.on the second click and from then on ,it shows 2.jpg.

I'd be thankful let me know what I'm doing wrong.

Many thanks,

Naseem
0
Dimitrina
Telerik team
answered on 20 Jul 2011, 01:00 PM
Hello Naseem,

 I have created a sample project using all the sample code you have posted. The filtering Control seems to be shown the right way.

Could you please review the project and then change it so that the wrong behavior occurs? 

Best wishes,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Naseem
Top achievements
Rank 1
answered on 21 Jul 2011, 07:35 AM
Hello Didie,

Thank you for generating a sample for the scenario. I have realized what cause the issue. In my application, in class MyFilteringControl, in Prepare method, if I remove the line which is related to theme , it works fine .

Telerik.Windows.Controls.StyleManager.SetTheme(this, new Office_BlueTheme());

Or even if I choose OfficeBlack theme still it works fine and filter text boxes will appear from the begining.

Even in your sample although it has been set with the Office blue theme , actually the result is still Silver color! In your sample the theme doesn't set to the filtering control .

The issue is because of Theme , but I don't know how I can fix it , since I need to set it to have Office Blue theme.

Many Thanks,

Kind Regards,
Naseem
0
Dimitrina
Telerik team
answered on 22 Jul 2011, 01:56 PM
Hello Naseem,

Unfortunately I am not able to apply this theme and get the wrong result.  Are you changing the theme of the GridView as well?

As I understand you change the Style of the entire filtering control, not just the filtering TextBoxes. If this is the case, may you please open a support ticket and send us a simple sample project?

Greetings,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Naseem
Top achievements
Rank 1
answered on 03 Aug 2011, 12:35 AM
Hello Didie,

I couldn't change the theme in your sample either. It's strange that with the same code the theme is changing in my code,not in yours!

However since the issue comes when the theme is changing (I mean when i remove the line for theme changing the filter control shows properly) I'm thinking may be the way I have changed the theme or the place I have set the theme, is not right. I was wondering if there is any other way to set theme for custom filter control?

public class CustomFilteringControl : FilteringControl
    {
        public override void Prepare(GridViewBoundColumnBase column)
        {
            base.Prepare(column);
  
            Telerik.Windows.Controls.StyleManager.SetTheme(this, new Office_BlueTheme());
  
            var vm = this.DataContext as FilteringViewModel;
  
            if (vm != null)
            {
                if (!vm.Filter1.IsActive)
                {
                    if (column.DataType.ToString().Contains("System.Int"))
                    {
                        vm.Filter1.Operator = FilterOperator.IsEqualTo;
                    }
                    else
                    {
                        vm.Filter1.Operator = FilterOperator.Contains;
                    }
                }
  
                if (!vm.Filter2.IsActive)
                {
                    if (column.DataType.ToString().Contains("System.Int"))
                    {
                        vm.Filter2.Operator = FilterOperator.IsEqualTo;
                    }
                    else
                    {
                        vm.Filter2.Operator = FilterOperator.Contains;
                    }
                }
            }
        }
    }

Many thanks,

Kind Regards,
Naseem 
0
Accepted
Rossen Hristov
Telerik team
answered on 03 Aug 2011, 02:31 PM
Hi Naseem,

You can do this in two ways:

1) In the constructor:

public class MyFilteringControl : FilteringControl
{
    public MyFilteringControl()
    {
        // This will be needed if you define an application theme
        this.DefaultStyleKey = typeof(FilteringControl);
         
        // Here you can set the theme. You could also do this in XAML like this:
        Telerik.Windows.Controls.StyleManager.SetTheme(this, new Office_BlueTheme());
    }
 
    public override void Prepare(GridViewBoundColumnBase column)
    {
        base.Prepare(column);
 
        Debug.WriteLine("MyFilteringControl.Prepare");
    }
}

2) In XAML:

<telerik:RadGridView Grid.Row="0"
                     Name="clubsGrid"
                     telerik:StyleManager.Theme="Office_Blue"
                     ItemsSource="{Binding Clubs}"
                     AutoGenerateColumns="False"
                     Margin="5">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">
            <telerik:GridViewDataColumn.FilteringControl>
                <my:MyFilteringControl telerik:StyleManager.Theme="Office_Blue"/>
            </telerik:GridViewDataColumn.FilteringControl>                 
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

I have attached a sample project.

Let me know if this does not help.

Best wishes,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Naseem
Top achievements
Rank 1
answered on 04 Aug 2011, 07:28 AM
Hi Didie,

Your solution worked :) I needed to set the theme in constructor.

Thank you so much for all your quick and helpful responses, I really appreciate it.

Best Regards,
Naseem
0
klogand
Top achievements
Rank 1
answered on 21 Sep 2011, 02:56 PM
I tried your project and get the default selection changed, but I'm losing my custom implicit styling (the default style is being shown) that I've defined in a separate XAML resource dictionary. How can I use this approach and keep my styling? I'm using version 2011.2.712.1040.
0
Dimitrina
Telerik team
answered on 26 Sep 2011, 12:11 PM
Hello Klogand,

We will need a little bit more information about your custom scenario. What is your custom styling? Do you apply it for the RadGridView, or for the FilteringControl?

Do you set the theme the same way as it is set in the sample project?

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
klogand
Top achievements
Rank 1
answered on 17 Feb 2012, 06:08 PM
Thanks,

This fell off the radar and I'm finally getting back to it, after we updated our controls to this version (2011.1.411.1040). I'm successfully hiding the Match case button in my custom style, but then when I apply the new CustomFilterControl as you described in the sample project zip above, the button comes back and the widths of the textbox change (see the attached before and after .jpgs). I have a FilteringControlStyle.xaml that overrides the default and uses an implicit style (the x:Key is not defined).

Once I added a key in the style file and called this.Style = Application.Current.Resources["FilteringControlStyle"] as Style; at the end of the Prepare method, it worked correctly. So I found my work around and I'm satisfied. Thanks for the sample that got me going. The style must not get applied because the type is myNamespace.CustomizedFilteringControl instead of telerk:FilteringControl?

It would be nice if the default could be set without overriding the whole control :-).
<Style TargetType="telerik:FilteringControl" BasedOn="{StaticResource filteringControlBase}">
      <Setter Property="Template" Value="{StaticResource FilteringTextControlTemplate}" />
   </Style>
 
    <Style x:Key="FilteringControlStyle" TargetType="telerik:FilteringControl" BasedOn="{StaticResource filteringControlBase}">
        <Setter Property="Template" Value="{StaticResource FilteringTextControlTemplate}" />
    </Style>
Tags
GridView
Asked by
Naseem
Top achievements
Rank 1
Answers by
Naseem
Top achievements
Rank 1
Dimitrina
Telerik team
Rossen Hristov
Telerik team
klogand
Top achievements
Rank 1
Share this question
or