Clear radigridview filter descriptors when datasource updated

7 posts, 1 answers
  1. JC
    JC avatar
    16 posts
    Member since:
    Oct 2015

    Posted 24 Nov 2016 Link to this post

    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

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    665 posts

    Posted 25 Nov 2016 Link to this post

    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.
  3. JC
    JC avatar
    16 posts
    Member since:
    Oct 2015

    Posted 25 Nov 2016 Link to this post

    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

  4. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    665 posts

    Posted 28 Nov 2016 Link to this post

    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.
  5. JC
    JC avatar
    16 posts
    Member since:
    Oct 2015

    Posted 29 Nov 2016 in reply to Stefan Nenchev Link to this post

    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

  6. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    665 posts

    Posted 29 Nov 2016 Link to this post

    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.
  7. JC
    JC avatar
    16 posts
    Member since:
    Oct 2015

    Posted 29 Nov 2016 in reply to Stefan Nenchev Link to this post

    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

Back to Top