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

FilterDescriptor Collection & Model-View-ViewModel

4 Answers 352 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick Anderson
Top achievements
Rank 1
Nick Anderson asked on 25 Aug 2009, 05:08 PM
I'm using an MVVM approach to an application.  My Window has a textbox, a button, and a grid.  When i click the button, i would like it to filter the grid based on the text inputted in the textbox.  I realize the grid has built in filtering, but its more than likely too complicated for our end users.

    <Grid> 
        <Grid.DataContext> 
            <Binding Source="{StaticResource MyDataContext}" Mode="OneWay"  /> 
        </Grid.DataContext> 
            <telerik:RadGridView  Margin="12,55,12,58" AutoGenerateColumns="True"    Name="RadGridView1" > 
              
            <telerik:RadGridView.ItemsSource> 
                <Binding Path="Records" Mode="TwoWay" /> 
            </telerik:RadGridView.ItemsSource>      
        </telerik:RadGridView> 
        <TextBox Height="23" HorizontalAlignment="Left" Margin="16,14,0,0" Text="{Binding SearchText}" Name="TextBox1" VerticalAlignment="Top" Width="120" /> 
        <Button Height="23" HorizontalAlignment="Right" Margin="0,14,61,0" Command="{Binding SearchCommand}" Name="Button1" VerticalAlignment="Top" Width="75">Button</Button> 
    </Grid> 

Is there any way to expose the FilterDescriptors Collection via  a binding property so i can add to it and apply the filter, since i don't have access to RadGridView1.FilterDescriptors in my code? This would be similar to how the textbox exposes it's text property.

Is there a way to expose the ColumnCollection or SortDescriptors?

4 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 31 Aug 2009, 08:28 AM
Hello Nick,

Currently we are not going to change the *ors and columns properties to be dependency properties. My suggestion is to have a FilterDescriptor property in your view model and then create a small controller class that will do the magic binding between the view (RadGridView) and the view model. You can also create a ColumnInfo class and use it in your ViewModel as a collection of column definitions. Then it will be the controller's responsibility to create the correct GridViewDataColumns based on the column infos.

Sincerely yours,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jebouy
Top achievements
Rank 1
answered on 15 Oct 2009, 10:02 AM
Hi,

 I am using MVVM pattern. I want to reset the Grids Filter on a button Click.
0
Rossen Hristov
Telerik team
answered on 15 Oct 2009, 02:28 PM
Hello jeb tom,

The only way to do this would be to attach to the button's click event and clear the GridViewDataControl.FilterDescriptors collection.

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.playersGrid.FilterDescriptors.Clear();
        }

I hope this helps.

Sincerely yours,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Saykor
Top achievements
Rank 2
answered on 25 Mar 2014, 11:31 AM
Or you can do:

<Button Command="{Binding ClearCommand}" CommandParameter="{Binding ElementName=RadGridView1}" />

ClearCommand= new RelayCommand<RadGridView>(ExecuteClearCommand);

private void ExecuteClearCommand(RadGridView grid)
        {
            grid.FilterDescriptors.Clear();
        }
Tags
GridView
Asked by
Nick Anderson
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Jebouy
Top achievements
Rank 1
Rossen Hristov
Telerik team
Saykor
Top achievements
Rank 2
Share this question
or