Pager apparently resets if Grid ItemsSource updated

4 posts, 0 answers
  1. Alex
    Alex avatar
    23 posts
    Member since:
    May 2005

    Posted 22 Sep 2011 Link to this post

    I'm pretty sure I am doing something wrong here but can't figure it out.

    My situation ;

    I have a RadGridView bound to a PagedCollectionView (DataList).
    <telerik:RadGridView x:Name="myGrid"  
              ItemsSource="{Binding DataList}"
              ColumnWidth="Auto" VerticalAlignment="Stretch"
              AutoGenerateColumns="False" HorizontalAlignment="Stretch"
              CanUserFreezeColumns="False"
              RowStyleSelector="{StaticResource selector}" >

     I also have a datapager that is connected to the grid via its Items property.
    <telerik:RadDataPager Grid.Row="1"
        x:Name="radDataPager"
        PageSize="15"
        Source="{Binding Path=Items, ElementName=myGrid}"
        DisplayMode="All"
        AutoEllipsisMode="Both"
        NumericButtonCount="10"
        IsTotalItemCountFixed="True"/>

    On initial load of the page, everything is fine.  I have 37 rows of data, I have 3 pages appearing in the pager. 

    Now, the nature of the data is such that it has some computed fields that are generated by a stored procedure after certain updates.  So, after a save operation is performed, I make a call to the DomainService using a LoadBehaviour of RefreshCurrent basically to refresh the cached entity set on the client (as outlined here).  The problem I am having is when that refresh completes, I recreate the PagedCollectionView in my view model which causes the grid to update it's itemssource via its binding.  The page however seems to disconnect or reset.  Basically I end up after the save and refresh with one page and all 37 records displayed in the grid.  Paging appears to be turned off.

    I hope this is clear and someone knows what I am doing wrong. 

    Thanks.
    Alex.
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 23 Sep 2011 Link to this post

    Hello Alex,

    I am not sure whether this would work, but can you try the following approach. Don't bind the pager to RadGridView.Items, but bind it directly to the PagedCollectionView property of your view model. You will have both RadGridView and RadDataPager bound to the PagedCollectionView.

    Another experiment that you might easily try -- replace RadDataPager with the stock Microsoft DataPager. Is it behaving the same way or differently? This can help us identify the culprit.

    Best wishes,
    Ross
    the Telerik team

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

  3. DevCraft banner
  4. Alex
    Alex avatar
    23 posts
    Member since:
    May 2005

    Posted 23 Sep 2011 Link to this post

    Thanks for the suggestions Ross.

    If I bind the RadDataPager directly to PagedCollectionView, then it seems to work.  This seems such an obvious thing to try, it did not occur to me.  This led me to try binding to the ItemsSource of the RadGrid instead of the Items property.  Again this appears to work as well.  Could it be that binding to the Items property is the culprit?  If so, examples are misleading as they instruct devs to bind to this property with the RadPager.

    In any event, thanks again for the pointers, they certainly helped me find what I was missing and reslove my issue.

    Alex.

  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 23 Sep 2011 Link to this post

    Hello Alex,

    This is when there are only pager and grid. Then the pager binds to the Items of the grid, since they are in fact an IPagedCollectionView (the grid internally creates something similar to the stock PagedCollectionView).

    But when you have an external PagedCollectionView like in your case, you should bind directly to it.

    Something like this in ASCII art:

    RadGridView  ----> PagedCollectionView <----- RadDataPager

    All the best,

    Ross
    the Telerik team

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

Back to Top