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

Using logical operator for filtering with the default filter provided by RadGrid

4 Answers 219 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mujiruddin
Top achievements
Rank 1
Mujiruddin asked on 20 Dec 2010, 02:48 PM

Hi,
I am trying to use the default filtering provided by RadGrid for silverlight (see attachment).
The filter ui allows me to specify a logical operation (AND/OR) across two criteria for a column.
I Have overridden the OnFiltering method on RadGridView to perform some operation when a filter is applied.
but the eventargs(GridViewFilteringEventArgs) does not contain the logical operation specified in the ui.

also the FilterDescriptors property on the RadGridView is empty when OnFiltering is executed,
but during OnFiltered the following code snippet

 

 

((Telerik.Windows.Data.CompositeFilterDescriptor)(((Telerik.Windows.Controls.GridView.ColumnFilterDescriptor)(this.FilterDescriptors[0])).FieldFilter)).LogicalOperator

evaluates to AND always.

is  there a way to get the value for the logical operator on application of the filter?

Thanks,
Mujir
 

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 21 Dec 2010, 10:58 AM
Hi Mujiruddin,

Unfortunately, this would not be possible right now, because you only get the leaf FilterDescriptors in the event arguments. For the next Latest Internal Build, we plan to add a reference to the actual ColumnFilterDescriptor in the event args, so you can take it an read all the information that it contains.

Let me try to explain this further. Each ColumnFilterDescriptor has the following structure:

      ColumnFilterDescriptor(AND)
      |                        |
DistinctFilter(OR)           FieldFilter(OR/AND)
  |         |                  |                                        |                                |
DV1 DV2 ... DVn            Filter1         Filter2

So, currently you can not distinguish what has really happened in the Filtering Event. If the user clicks checks a distinct value you will get its FilterDescriptor in e.Added. Similarly, if the user types something in Filter 1 text-box you will get the FilterDescriptor in e.Added. But you can't discern what has really happened.
This is due to some legacy issues and we have plans to refurbish the whole filtering architecture. We have left the Filtering and Filtered event arguments the way they are for backwards compatibility purposes. But as you can see the actual e.Added and e.Removed are kind of fake.

When we add a reference to the whole big ColumnFilterDescriptor you will be able to do the following:

var operator = e.ColumnFilterDescriptor.FieldFilter.LogicalOperator;

This will be the operator you are looking for.

This feature will make it for the next "Latest Internal Build". Let us know if there are problems after you upgrade to it.

Regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Mujiruddin
Top achievements
Rank 1
answered on 21 Dec 2010, 11:38 AM
Thanks ross,

Is there a way by which i can remove the OR option from the UI?

Mujir.
0
Accepted
Rossen Hristov
Telerik team
answered on 21 Dec 2010, 12:25 PM
Hello Mujiruddin,

Yes there is. I have prepared a sample project that does this. It uses the fact that you can derive from the stock control and alter its behavior. Here is how I did it, but you can choose anything else to do with the combo depending on your requirements:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using System.Linq;
using System.Windows.Data;
using System.Collections.Generic;
 
namespace RemoveORFromFieldFilter
{
    public class CustomizedFilteringControl : FilteringControl
    {
        public override void Prepare(GridViewBoundColumnBase column)
        {
            base.Prepare(column);
 
            var vm = this.DataContext as FilteringViewModel;
 
            if (vm != null)
            {
                var fieldFilterCombo = this.ChildrenOfType<RadComboBox>()
                    .Where(combo => combo.Name == "PART_LogicalOperatorsComboBox")
                    .FirstOrDefault();
 
                // In case you want to simply hide the combo...
                //if (fieldFilterCombo != null)
                //{
                //    fieldFilterCombo.Visibility = Visibility.Collapsed;
                //}
 
                // In case you want it to show, but have only AND available.
                fieldFilterCombo.ItemsSource = new List<FilterCompositionLogicalOperator>() { FilterCompositionLogicalOperator.And };
                fieldFilterCombo.IsEnabled = false;
 
                // In fact, once you have the combo you can decide to do anything with it.
            }
        }
    }
}

The other way in which you can do this would be to edit the FilteringControl template and hide the logical operator combo. You can specify the new control template through the FilteringControlStyle property of the column.

Both of these approaches will do the job. Let me know if there are problems.

Best wishes,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Mujiruddin
Top achievements
Rank 1
answered on 21 Dec 2010, 02:13 PM
Thanks, that works.

Mujir.
Tags
GridView
Asked by
Mujiruddin
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Mujiruddin
Top achievements
Rank 1
Share this question
or