Sorting and Filtering with different ViewModels

7 posts, 0 answers
  1. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 06 Aug 2014 Link to this post

    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
  2. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 06 Aug 2014 Link to this post

    Hi,
    i upload a sample project.
    http://project-free-upload.com/otknldzz7avk
    Ivan
  3. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Aug 2014 Link to this post

    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.
     
  4. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 06 Aug 2014 in reply to Dimitrina Link to this post

    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
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Aug 2014 Link to this post

    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.
     
  6. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 14 Aug 2014 in reply to Dimitrina Link to this post

    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
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Aug 2014 Link to this post

    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.
     
Back to Top