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

Sorting and Filtering with different ViewModels

6 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 06 Aug 2014, 09:38 AM
Hi,

i have a problem with sorting and filtering. In my project i want to display a collection, in which are the items from different class type but have some same-named properties.
i.e.
ViewModelClassA : ViewModelBase
ViewModelClassB : ViewModelBase
ViewModelClassC : ViewModelBase
they all have the properties: Name, Description, Comment.
So i displayed this collection and want to use the sorting and filtering functions. Aber the filter and the sorting effect will not be shown.
I have tried to just take one type of my class, then everything is ok. I see the filter and the sorting effect.

Is there a discussion about this problem or even better there is already a solution for that? Thanks a lot!

Ivan

6 Answers, 1 is accepted

Sort by
0
Ivan
Top achievements
Rank 1
answered on 06 Aug 2014, 09:52 AM
Hi,
i upload a sample project.
http://project-free-upload.com/otknldzz7avk
Ivan
0
Dimitrina
Telerik team
answered on 06 Aug 2014, 11:47 AM
Hi Ivan,

I am not able to download the project from the link. Would you please upload it in some other repository or open a new support thread and attach it there?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ivan
Top achievements
Rank 1
answered on 06 Aug 2014, 01:04 PM
Hi Didie,

here is the project.
http://www.file-upload.net/download-9333864/RadGridView_WPF_AR_60.rar.html

Perhaps i have a solution. I'll build a container for the different ViewModels and pass the properties. Because in my project i cant abstract the properties in my base class.

Another problem - with CellTemplate i have also problem with sorting and filtering. I need some suggestion.

Thanks!

Ivan
0
Dimitrina
Telerik team
answered on 06 Aug 2014, 03:07 PM
Hello,

I am again having a problem downloading the file, you can check the attached image. Would you please open a new support thread and attach the demo there?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ivan
Top achievements
Rank 1
answered on 14 Aug 2014, 02:05 PM
Hello,
i have removed folder bin and obj. Please try again, thanks.
http://www.file-upload.net/download-9376079/RadGridView_WPF_AR_60.rar.html
0
Dimitrina
Telerik team
answered on 15 Aug 2014, 11:48 AM
Hello,

Thank you, it seems the .exe file in was blocked by my anti virus system. I run your solution and after adding an item of type ClubB, I am able to reproduce the issue.
Sorting and Filtering are data operations, they are actually done by building and executing a LINQ query over the source collection. 

For example, when sorting on the Name property of the bound item, the generated query would be:
var result = viewSource.OrderBy(x => x.Name);

In your case the base class ClubBase do not have the respective properties (Name, Established and
StadiumCapacity) and that is why we cannot build and execute a query based on those properties over the list of ClubBase objects. That is why there is no filtering icon shown and the sorting and grouping are also not working

When all the items are of type ClubA, then RadGridView is smart enough to take ClubA as type of the items instead of ClubBase. When there are different type of items though, we cannot do so as we do not know which type to get.

You need to design your data so that you to be able to build and execute such a query. 

Then, you can also specify the ItemType explicitly:

public MainWindow()
{
    InitializeComponent();
    this.clubsGrid.Items.ItemType = typeof(ClubBase);
}

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Ivan
Top achievements
Rank 1
Answers by
Ivan
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or