Get sorted source

6 posts, 0 answers
  1. Krzysztof
    Krzysztof avatar
    3 posts
    Member since:
    Mar 2014

    Posted 08 Jun 2015 Link to this post

    Hi,

     
    I'm using RadDataPager with RadGridView. I need to access sorted source in RadDataPager after click on column header of my RadGridView.

    Below is my code:

     
    <telerik:RadGridView ItemsSource="{Binding PagedSource, ElementName=pager}" CanUserSortColumns="True" AutoGenerateColumns="True" />

    <telerik:RadDataPager x:Name="pager" PageSize="25" Source="{Binding RecordsItemsSource}"
     IsTotalItemCountFixed="False"
     DisplayMode="All"
     NumericButtonCount="10" />

     
    Where RecordsItemsSource is ObservableCollection in my ViewModel.

    Thanks in advance,
    Kris

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 Jun 2015 Link to this post

    Hello Kris,

    RadDataPager itself does not hold a sorted collection. You can access the same from RadGridView.Items. You can also find the current sort descriptors applied through 
    RadGridView.SortDescriptors collection.

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Krzysztof
    Krzysztof avatar
    3 posts
    Member since:
    Mar 2014

    Posted 10 Jun 2015 Link to this post

    Thanks Dimitrina for your reply.

     

    In RadGridView.Items I can find items only in actual page, not all items.

    I tried to use RadGridView.SortDescriptors and CollectionViewSource to sort base collection. Unfortunately sorting by RadGridView gives me diffrent collection for this same values. For example:

    Name: John, Age: 17

    Name: Piter, Age: 16

    Name: Rita, Age: 15

    Name: Jenny, Age: 16

    When I sort on "Age"

    RadGridView return: Rita, Jenny, Piter, John

    CollectionViewSource with RadGridView.SortDescriptors return: Rita, Piter, Jenny, John

    If "RadDataPager itself does not hold a sorted collection", how RadDataPager knew which items gives to RadGridView on actual page? RadDataPager sort base collection on every time when I change page?

    Thanks in advance,
    Kris

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 11 Jun 2015 Link to this post

    Hi Kris,

    I will try to explain the way RadDataPager works in some further details.  Every time you navigate to a page, it internally builds a LINQ query appending Skip and Take clauses and then this query is to be executed on the server. When binding the pager to a LINQ-enabled data source (i.e. IQueryable), the paging will happen on the server out-of-the-box. In case the pager is bound to an IQueryable, it will automatically append Skip(n) and Take(m) statements to this query.

    Similarly, sorting in RadGridView is a data operation and we internally generate and execute a LINQ query appending a OrderBy clause to the source collection. 

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

    Then, when using sorting and paging, there is a proper LINQ query built, the method 'OrderBy' must be called before the method 'Skip'.

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Sheena
    Sheena avatar
    1 posts
    Member since:
    Oct 2013

    Posted 24 Jul 2015 Link to this post

    I have a similar situation for this issue and I am able to get the Sort Direction (Ascending or Descending) of the Column but not able to get the Column Name that is being Sorted (Customer Name or Account Number).  How are you able to get this information?  I can see the Column Name while in Debug Mode but not able to retrieve it.

    Thanks!

  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Jul 2015 Link to this post

    Hello,

    You can access it like so:
    ColumnSortDescriptor sorting = this.clubsGrid.SortDescriptors.FirstOrDefault() as ColumnSortDescriptor;
    if (sorting != null)
    {
        var column = sorting.Column as GridViewDataColumn;
        string name = column.Header.ToString();
    }

    I hope this helps.

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner