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

Re-binding RadGridView without loosing filters

4 Answers 369 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fredrik
Top achievements
Rank 1
Fredrik asked on 23 Aug 2017, 02:45 PM

Hello,

I have an application that follows the MVVM pattern that contains data presented in different RadGridView items.

My grids are bound to different QueryableCollectionViews exposed as IEnumerable properties in a view model.

Lets say I have a refresh-button that grabs data from a webapi and I want to update the grids with it.
Is there a way to refresh the QueryableCollectionView with the data without loosing filters, groupings etc?

Today I re-create my QueryableCollectionViews and manually add possible filters etc. The issue I'm having right now is that while the filters do work, the funnel icons for the filtered columns does not light up, so the client might not realise the grid is filtered.

 

Is there an easy way around this?

Thanks in advance,
Fredrik

4 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 28 Aug 2017, 10:41 AM
Hello Fredrik,

Indeed, the described behavior would be expected as you are resetting the source collection of RadGridView. This is by design, as there is no guarantee that the type of the newly added items would match the descriptors and columns already defined. So, your approach is the right one. As for the lighting-up problem of the filter funnel - this is probably because you are adding FilterDescriptor. Can you try ColumnFilterDescriptor instead?

Regards,
Yoan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Fredrik
Top achievements
Rank 1
answered on 30 Aug 2017, 10:53 AM

Hello!

Thank you for the reply. I have not been successful in my attempts to resolve the funnel issues.
Just to make sure I understood you correctly, this is basically what I did;

private QueryableCollectionView view;

public void RefreshGrid()
{
    // ... grab data etc

    // Get current filters
    var filters = this.view?.FilterDescriptors?.Select(o => o as IColumnFilterDescriptor).ToList();

    // Re-create the view
    this.view = new QueryableCollectionView(this.DataCollection);

    // Add possible filters
    if (filters?.Any() ?? false)
    {
        this.view?.FilterDescriptors.AddRange(filters);
    }
}

The grid applies the filters correctly but the funnel icons is still not lit. 

 

Kind regards,

Fredrik

0
Accepted
Yoan
Telerik team
answered on 04 Sep 2017, 07:16 AM
Hi Fredrik,

Actually, you can not add ColumnFilterDescriptors since you are working with the FilterDescriptors of the QCV. Please excuse me if I misled you.

I have tried to reproduce the problem with the filter funnel but to no avail. I've created a sample project using your code snippet. Can you please check it and let me know what I am missing?

Regards,
Yoan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Fredrik
Top achievements
Rank 1
answered on 13 Sep 2017, 01:35 PM
Hello and sorry for the late reply!

I have looked at your project and I did find some issues in my code.
I think the main issue was that my QueryableCollectionView object was publicly exposed as an IEnumerable. 

Tags
GridView
Asked by
Fredrik
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Fredrik
Top achievements
Rank 1
Share this question
or