We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfDataPager UseOnDemandPaging

Hello,
I don't understand how SfDataPager's UseOnDemandPaging works. Here's my (your default) code:

                         I have not set sfDataPager.Source as said in overview !

            sfDataPager.UseOnDemandPaging = true;
            sfDataPager.OnDemandLoading += (s,e) =>//SfDataPager_OnDemandLoading;
            {
            sfDataPager.LoadDynamicItems(e.StartIndex, (lItemsSource as IEnumerable<T>).Skip(e.StartIndex).Take(e.PageSize));
            };

lItemsSource as IEnumerable<T> is my items source which works when I set sfDataPager.Source. But when I use OnDemandLoading, I get (on breakpoint) Source = null, PagedSource = null, PageCount = 0. I have tried to put this in OnDemandLoading just to see if items source is OK:
     var lList = (lItemsSource as IEnumerable<T>).Skip(e.startIndex).Take(e.PagedSize)
and I got valid result as it should be, but I still get
Source = null, PagedSource = null, PageCount = 0.
Why do I need this? I want to be able to go to, for example, 4th page when I load sfDataGrid.

Also, if data pager has 20 pages and NumericButtonCount e.g. 5, when I say sfDataPager.PageIndex = 13, it does not refresh the view of data pager, so only first 5 buttons are in the view and when Next is pressed it goes to index 14 and then refreshes the view (I have tried this independently from this matter above, but I assume same thing will happen when OnDemandLoading starts working for me).

I would appreciate any explanation or help on this matter. Thanks in advance.

1 Reply

SS Sivaraman Sivagurunathan Syncfusion Team April 4, 2017 01:13 PM UTC

Hi Stanicb,

Thank you for using Syncfusion Products.

Regarding your query on how to use OnDemandPaging in SfDataGrid:

If you don’t set the UseOnDemandPaging property for the SfDataPager, the data collection(all page data) is entirely loaded initially to the SfDataPager. If you set the UseOnDemandPaging  property as “True” for the SfDataPager, then the current page data only will be loaded and the other page data are loaded dynamically by hooking the OnDemandloading event. In the OnDemandloading event, use the LoadDynamicItems  method to load the data for the corresponding page in SfDataPager dynamically.

When you use OnDemandPaging, SfDataPager.PagedSource loads only the current page data. Upon navigation to another page, OnDemandLoading event is fired which loads another set of data but maintains the previous page data also. When you navigate to previous page again, OnDemandLoading event will not fire as the data loaded would be maintained in cache. However for further performance enhancement if you do not want to maintain the previous page data, you can call Syncfusion.Data.PagedCollectionView.ResetCache() in OnDemandLoading event. ResetCache method call resets the cache except current page. 
And you have to set the SfDataPager.Source because when paging is enabled we populate the data for SfDataGrid through the SfDataPager hence setting the Source in SfDataPager is mandatory. 
 
Also Refer the UG Link:  https://help.syncfusion.com/xamarin-android/sfdatagrid/paging#on-demand-paging

Regarding the reported issues: 
We confirm that the issue “SfDataPager view initially not refresh when we set the PagedIndex for the SfDataGrid ” is a defect and we are able to reproduce the issue. The fix for this issue will be available in our upcoming 2017 Volume 2 Main Release scheduled for roll out in the last week of April. We appreciate your patience until then.

Thanks & Regards,

Sivaraman  
 


Loader.
Up arrow icon