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

[Solved] Doing OR filtering across columns within the grid

1 Answer 99 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.
Mujiruddin
Top achievements
Rank 1
Mujiruddin asked on 15 Feb 2011, 10:02 AM
As I understand it, right now, there are two ways of applying filtering on a RadGridView.
  1. Click on the filter icon on a particular column and set filters. If you set filters on multiple columns, then the grid will show rows which match the filter criteria of all the columns - so this is AND filtering across columns
  2. Use the new DataFilter control - here you can choose between AND and OR filtering across columns, but the filtering is more complicated than directly adding the filters to the columns.
I don't have a particular UI in mind, but are there any suggestions which can combine the advantages of being able to specify the filters directly on the grid columns and being able to OR across columns? Is such a control part of the Telerik Silverlight controls' roadmap? If so when would something like this be available and where can I take a look at the demo?
Thanks,
Mujir

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 16 Feb 2011, 11:52 AM
Hello Mujiruddin,

You can do this like that:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using Telerik.Windows.Controls.GridView;
 
namespace FilterColumnsWithOR
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            this.grid.Items.FilterDescriptors.LogicalOperator = FilterCompositionLogicalOperator.Or;
            this.grid.DistinctValuesLoading += this.OnDistinctValuesLoading;
        }
 
        private void OnDistinctValuesLoading(object sender, GridViewDistinctValuesLoadingEventArgs e)
        {
            // By passing false as the second parameter here you are telling the grid
            // to return absolutely ALL distinct value no matter what the currently applied
            // filter are. This is suitable when you want to combine filter with OR.
            e.ItemsSource = this.grid.GetDistinctValues(e.Column, false);
        }
 
    }
}

<UserControl x:Class="FilterColumnsWithOR.MainPage"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:my="clr-namespace:FilterColumnsWithOR"
             mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="700">
    <UserControl.Resources>
        <my:MyViewModel x:Key="MyViewModel"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"
          Background="White"
          DataContext="{StaticResource MyViewModel}">
        <telerik:RadGridView Name="grid" ItemsSource="{Binding Clubs}"/>
    </Grid>
</UserControl>

I have attached a simple project with this code.

I hope this helps.

All the best,
Ross
the Telerik team
Tags
GridView
Asked by
Mujiruddin
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or