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

Clear radigridview filter descriptors when datasource updated

6 Answers 446 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JC
Top achievements
Rank 1
JC asked on 24 Nov 2016, 10:20 AM

Hello
Because some action on my window alters datacontext attached to a radigridview, I need to reset applied filter when datasource is altered.
I tried to launch command myGried.FilterDescriptors.Clear(); on SourceUpdated, DatacontextChange and DataLoaded event, but the first 2 aren't raised when RaisePropertyChange is raised, the last one (DataLoaded event) is raised but when I tried to clear FilterDescriptors, I got error that I can't alter datasource when loading.

Any idea how can I clear FilterDescriptors when datacontext change?

Thanks

6 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 25 Nov 2016, 08:38 AM
Hi,

I am not absolutely sure of your setup but the DataContextChanged event works fine at my end and is the most convenient  event to use for your requirement. I have attached a sample project for your reference. What is the difference in your actual sample? You can also try to clear the FilterDescriptors when the DataContext is changing. What is the action that changes the DataContext? 

Regards,
Stefan Nenchev
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
JC
Top achievements
Rank 1
answered on 25 Nov 2016, 10:55 AM

Hi Stefan,

Thanks for your answer, yes your solution works in your solution but not in mine.

I think I wrote a mistake in my first post. In fact it's not datacontext which is altered, this is ItemsSource property which is changed with a RaisePropertyChanged() like in the piece of code below :

in view xaml :

<telerik:RadGridView x:Name="GridViewStresses"  ShowGroupPanel="False" CanUserFreezeColumns="False" ItemsSource="{Binding SynthesisData}"
                           IsFilteringAllowed="true" RowIndicatorVisibility="Collapsed" CanUserReorderColumns="False" CanUserResizeColumns="False" IsReadOnly="True"
                           Margin="10" CanUserSortColumns="True" CanUserDeleteRows="False" AutoGenerateColumns="False" Width="Auto" CanUserInsertRows="False" CanUserResizeRows="False" CanUserSelect="False" CanUserSortGroups="False">
    <telerik:RadGridView.Columns>
        ...
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

in view model.vb :

Me.SynthesisData = Me._tempData.OrderByDescending(Function(d) d.Ratio).ToList()
RaisePropertyChanged(Function() Me.SynthesisData)

 

in this case the DatacontextChanged event is not raised.

 

thanks 

regards

0
Stefan Nenchev
Telerik team
answered on 28 Nov 2016, 03:14 PM
Hello ,

Thanks for the clarification. Indeed, the DataContextChanged event would not be fired in such case. You can expose a boolean property on your ViewModel that would tell that the ItemsSource is changed. Eventually, you can extend the RadGridView and add a DependencyProperty that will be bound to this boolean property and in its callback to clear the FilterDescriptors collection. Have a look at the attached sample project(C# and VB versions). You can accustom it to your specific case.

Regards,
Stefan Nenchev
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
JC
Top achievements
Rank 1
answered on 29 Nov 2016, 10:29 AM

Hello Stefan
Thanks for your answer, it partially works but I still have a little trouble like you have with your project.
The applied filter is cleared so the source item is the right one but the checkbox filter is still checked as you can see in the attached screen print.
Regards
J-Christophe

0
Accepted
Stefan Nenchev
Telerik team
answered on 29 Nov 2016, 12:52 PM
Hello J-Christophe,

The following change should do:

private static void ItemsSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
       {
           var grid = d as CustomRadGridView;
 
           grid.FilterDescriptors.SuspendNotifications();
           foreach (var col in grid.Columns)
           {
               col.ClearFilters();
           }
           grid.FilterDescriptors.Clear();
           grid.FilterDescriptors.ResumeNotifications();
 
           grid.ItemsSourceChanged = false;
       }

Regards,
Stefan Nenchev
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
JC
Top achievements
Rank 1
answered on 29 Nov 2016, 01:07 PM

Thans for your quick answer Stefan, it works.

If someone needs the vb code, here the code I used :

Private Shared Sub ItemsSourceChangedCallback(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
      Dim grid As CustomRadGridView = TryCast(d, CustomRadGridView)
      grid.FilterDescriptors.SuspendNotifications()
      For Each col As GridViewColumn In grid.Columns
        col.ClearFilters()
      Next
      grid.FilterDescriptors.Clear()
      grid.FilterDescriptors.ResumeNotifications()
      grid.ItemsSourceChanged = False
End Sub

 

Regards

J-Christophe

Tags
GridView
Asked by
JC
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
JC
Top achievements
Rank 1
Share this question
or