Sorting across pages?

4 posts, 0 answers
  1. Nick
    Nick avatar
    7 posts
    Member since:
    Aug 2011

    Posted 07 Nov 2011 Link to this post

    The RadDataPager works great for us, especially when it comes to speeding up the loading time for our records on the main page of our app (we were loading all of our records at the same time before, and there are a lot of them).

    However, is it possible to sort data across pages when you're using the RadDataPager? Currently, when a user clicks on a column header in the RadGridView, it just sorts the records on that page. Would there be a way to sort all of the records across all pages when a user clicks a column header?

    I'm assuming that we'll have to implement our own custom logic to get this to work, and I'm also assuming that we won't be able to get around the fact that we'll have to load all of the records in the gridview again, but I'm just wondering if anyone has found an efficient way to do this.

    Thanks!

  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 07 Nov 2011 Link to this post

    Hi Nick,

    Can you please share how have you connected RadGridView and RadDataPager?

    If you data-bind RadDataPager.Source to RadGridView.Items you should get the behavior that you have described.

    Best wishes,
    Ross
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Nick
    Nick avatar
    7 posts
    Member since:
    Aug 2011

    Posted 21 Nov 2011 Link to this post

    Thanks for the reply. 

    Looking back on it now, I didn't truly connect the RadGridView and the RadDataPager in any way. Here is the xaml code for the RadDataPager:

    <telerikPager:RadDataPager x:Name="rgvInventory_Pager" DisplayMode="All" PageSize="32"
                                       Margin="6,0,6,25" Width="749" Height="28" VerticalAlignment="Bottom" PageIndexChanged="rgvInventory_Pager_PageIndexChanged"/>

    In the constructor of the window that uses it, I simply set its Itemcount:

    rgvInventory_Pager.ItemCount = DataAccess.GetEquipmentCount();

    When I load the actual equipment data, I just set the ItemsSource of the RadGridView ("rgvInventory"). I don't actually set the ItemsSource of the RadDataPager ("rgvInventory_Pager"):

    rgvInventory.ItemsSource = result;
    rgvInventory.IsBusy = false;

    And this is how the data is actually loaded - it's only loaded by page:

     public static IEnumerable<Equipment> GetEquipmentByPage(int page, int pageSize)
     {
    lock (database)
    {
    return database.Equipments
                        .OrderByDescending(i=>i.Id)
                        .Skip((page - 1) * pageSize).Take(pageSize);
    }
    }

    The fact that we're only loading some of the records rather than all of them is what saves us time. It's unavoidable that we're going to have to load all of the equipment in order to sort all of it, right? I can set the RadDataPager's Source to be the RadGridView's Items collection, but that Items collection still needs to have everything if you want to sort all of the data. I know it's kind of a dumb question, but I'm just wondering if there are any tricks with the RadDataPager that might make dealing with this a little easier.

    Thanks
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 22 Nov 2011 Link to this post

    Hello Nick,

    So it seems that you are using RadDataPager in its Unbound Mode.

    I am afraid that there is no magic way to sort all the data without actually having it.

    Kind regards,
    Ross
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top