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

How create multiply filter?

15 Answers 197 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton Samarin
Top achievements
Rank 1
Anton Samarin asked on 14 Jan 2009, 06:21 AM
Hello!
Could you tell, how i can programmatically  create filter by two (for example) columns? Is it possible?

Thx

15 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 17 Jan 2009, 03:14 PM
Hello Anton,

Yes, that is possible. The programmatic filtering entry point for RadGridView is the FilterDescription property -- you either provide your own, or configure the autogenerated CompositeFilterDescription. The latter contains a collection of FieldFilterDescription objects each defining the filter for the currently displayed columns. Here is how to define a filter by two columns:

public partial class Window1 : Window 
    public Window1() 
    { 
        InitializeComponent(); 
 
        RadGridView1.ItemsSource = new Message[] {  
            new Message { Sender = "tom@hanna-barbera.com", Subject = "Cats are cool", Size = 100 }, 
            new Message { Sender = "jerry@hanna-barbera.com", Subject = "Mice are cool", Size = 100 }, 
            new Message { Sender = "spike@hanna-barbera.com", Subject = "Dogs are cool", Size = 100 } 
        }; 
 
 
    } 
 
    private void filterButton_Click(object sender, RoutedEventArgs e) 
    { 
        var masterFilter = (CompositeFilterDescription) (this.RadGridView1.FilterDescription); 
         
        var subjectFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[0]; 
        subjectFilter.Values.Add("Cats are cool"); 
        subjectFilter.Values.Add("Mice are cool"); 
 
        var senderFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[1]; 
        senderFilter.Values.Add("jerry@hanna-barbera.com"); 
    } 

Alternatively you can inherit from FilterDescription and create your own custom filtering. Our Custom Filtering example shows how to do that.

All the best,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Samarin
Top achievements
Rank 1
answered on 28 Jan 2009, 11:59 AM
Hello,
Do not uderstand your answer, for example:
If i comment-out '//subjectFilter.Values.Add("Mice are cool");' in your solution, then after click 'filterButton' return 1 row, but for filter 
var masterFilter = (CompositeFilterDescription) (this.RadGridView1.FilterDescription);
var subjectFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[1];
subjectFilter.Values.Add("Cats are cool");
var senderFilter = (FieldFilterDescription) masterFilter.FilterDescriptions[1];
senderFilter.Values.Add("jerry@hanna-barbera.com");
and value 
   RadGridView1.ItemsSource = new Message[] { 
new Message { Sender = "tom@hanna-barbera.com", Subject = "Cats are cool", Size = 100 },
new Message { Sender = "jerry@hanna-barbera.com", Subject = "Mice are cool", Size = 100 },
new Message { Sender = "spike@hanna-barbera.com", Subject = "Dogs are cool", Size = 100 }
};

it must return 0 row, i think.

Thx for your time.
0
Hristo Deshev
Telerik team
answered on 28 Jan 2009, 01:10 PM
Hi Anton Samarin,

Your code does not get the correct filter description for the subject filtering. Instead of using masterFilter.FilterDescriptions[1], you must use masterFilter.FilterDescriptions[0]. Changing that, returns 0 rows on my end.

All the best,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Samarin
Top achievements
Rank 1
answered on 29 Jan 2009, 07:55 AM
Hello
Sorry for my mistakes.
I would like to see a different result after filtering. I found the demo solution of your presentation CustomFilterTemlate. I want to search is not complete integration but partial.
for value 'Name1','Name2','Name22','Name12','Name21', and filter 'name2' result 'Name2','Name22','Name21'.

Tnx
0
Anton Samarin
Top achievements
Rank 1
answered on 05 Feb 2009, 10:42 AM
Hello,
Could you tell, Can I get this effect for a multiplicity of filters?

0
Accepted
Hristo Deshev
Telerik team
answered on 05 Feb 2009, 12:54 PM
Hi Anton Samarin,

I think I understand what you are trying to achieve here -- to reiterate: you need multi-column filtering that matches string in a case insensitive manner.

I've done that in a sample that:
  1. Uses a custom filter description: StringContainsFilterDescription. It uses reflection to get the value from the associated property and detect if the filter value is contained in the property value:

    public override bool SatisfiesFilter(object dataItem) 
        //the line below needs better error checking and works for string properties only 
        var value = (string) TypeDescriptor.GetProperties(dataItem)[this.PropertyName].GetValue(dataItem); 
     
        if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(this.FilterValue)) 
        { 
            return value.ToUpper().Contains(this.FilterValue.ToUpper()); 
        } 
        else 
        { 
            return string.IsNullOrEmpty(this.FilterValue); 
        } 
  2. We use two descriptions composed in a CompositeFilterDescription object.
  3. The two descriptions' filter values are obtained from two text boxes. That is why I have declared the filter descriptions in XAML and I am using a plain WPF binding to transfer the textbox Text property as a filter value:

    <Window.Resources> 
        <local:StringContainsFilterDescription x:Key="SenderFilter" PropertyName="Sender" /> 
        <local:StringContainsFilterDescription x:Key="SubjectFilter" PropertyName="Subject" /> 
    </Window.Resources> 
     

Best wishes,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Samarin
Top achievements
Rank 1
answered on 10 Feb 2009, 10:56 AM
Thank you for your reply. This is almost what I wanted to see
0
nbahl
Top achievements
Rank 1
answered on 24 Feb 2009, 05:04 PM
Is it possible to have a single filter textbox and when filtering it will return all rows that have that value in any column?   Thanks.
0
Valeri Hristov
Telerik team
answered on 25 Feb 2009, 12:01 PM
Hello Nate,

Please, find a simple example that demonstrates how to achieve your requirement. Let me know if it does not work for you.

All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Anton Samarin
Top achievements
Rank 1
answered on 27 Feb 2009, 08:11 AM
Hello,
I found a strange behavior of grid. 
If you for your sample project "programmaticcustomfilter" will use in mainwindow xaml this code:
<TabControl>
            <TabItem Header="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.152*"/>
                    <RowDefinition Height="0.152*"/>
                    <RowDefinition Height="0.152*"/>
                    <RowDefinition Height="0.848*"/>
                </Grid.RowDefinitions>
                <TextBox Grid.Row="0" Text="{Binding Source={StaticResource SenderFilter}, Path=FilterValue}"></TextBox>
                <TextBox Grid.Row="1" Text="{Binding Source={StaticResource SubjectFilter}, Path=FilterValue}"></TextBox>
                <Button Content="Filter" Grid.Row="2" x:Name="filterButton" Click="filterButton_Click"/>
                <telerik:RadGridView Name="RadGridView1" Grid.Row="3" />
            </Grid>
        </TabItem>
            <TabItem Header="2">
                
            </TabItem>
        </TabControl>

i just added tabcontrol and located into first tabitem your grid. Then you move to second tab and back to first,  you'll see that data will not show in row.

Thanks.
0
Valeri Hristov
Telerik team
answered on 27 Feb 2009, 05:34 PM
Hi Anton,

This is a known problem in RadGridView that has been fixed in our internal builds. The fix will be available in the official release of RadControls for WPF that is scheduled for the mid March.

Kind regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Anton Samarin
Top achievements
Rank 1
answered on 02 Mar 2009, 02:49 AM
Valeri, thank you very much.
0
Orit
Top achievements
Rank 1
answered on 07 Jun 2009, 08:13 AM

I tried to use this code
when I open the all project it works
but when I copy the code to my projet I get this error-

Error 1 'Telerik.Windows.Data.FieldFilterDescription' does not contain a definition for 'Values' and no extension method 'Values' accepting a first argument of type 'Telerik.Windows.Data.FieldFilterDescription' could be found (are you missing a using directive or an assembly reference?) 

for this row 

 

subjectFilter.Values.Add(

"Cats");

 

 

 

0
Vlad
Telerik team
answered on 08 Jun 2009, 05:56 AM
Hello Orit,

I didn't found any subjectFilter and Values.Add in the posted project - can you clarify?

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Orit
Top achievements
Rank 1
answered on 08 Jun 2009, 09:23 AM
I copy-paste this code to my project

var

 

masterFilter = (CompositeFilterDescription)(this.RadGridView2.FilterDescription);

 

 

var subjectFilter = (FieldFilterDescription)masterFilter.FilterDescriptions[0];

 

subjectFilter.Values.Add(

"Cats are cool");

 

subjectFilter.Values.Add(

"Mice are cool");

 

 

var senderFilter = (FieldFilterDescription)masterFilter.FilterDescriptions[1];

 

senderFilter.Values.Add(

"jerry@hanna-barbera.com");

but I get an error
'Telerik.Windows.Data.FieldFilterDescription' does not contain a definition for 'Values'
and no extension method 'Values' accepting a first argument of type 'Telerik.Windows.Data.FieldFilterDescription'
could be found (are you missing a using directive or an assembly reference?) 

what I am looking for, is a simple code to filter by two columns.

Thanks.

 

Tags
GridView
Asked by
Anton Samarin
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
Anton Samarin
Top achievements
Rank 1
nbahl
Top achievements
Rank 1
Valeri Hristov
Telerik team
Orit
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or