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.
SSSivaraman Sivagurunathan Syncfusion Team April 4, 2017 01:13 PM UTC
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.PagedSourceloads only the current page data. Upon navigation to another page, OnDemandLoadingevent 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.
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.