Programmatically Processing Paging in UWP DataPager (SfDataPager)
10 May 20213 minutes to read
Changing PageIndex at runtime
SfDataPager exposes the PageIndex property, which denotes the index of currently selected page. You can use this property to set or get the current page of the SfDataPager
.
Event | Description |
---|---|
Event triggered before the current page index changed. By using this event, you can cancel the current page changing operation by setting `Cancel` to `true`. | |
Event triggered after the current page index changed. |
Programmatically changing PageCount
SfDataPager allows you to change the current page using PageCount property. you can change the PageCount
during the run time.
Changing PageIndex using method
SfDataPager allows you to change the current page using built-in methods. For example, you can change the PageIndex
to last page by calling MoveToLastPage() method.
SfDataPager
provides the following methods for changing current page.
Method | Prototype | Description |
---|---|---|
MoveToFirstPage() | This method moves the current page index to the first page and displays the first page data. | |
MoveToLastPage() | This method moves the current page index to the last page and displays the last page data. | |
MoveToNextPage() | This method moves the current page index to the next page and displays the next page data. | |
MoveToPreviousPage() | This method moves the current page index to the previous page and displays the previous page data. | |
MoveToPage(int pageIndex) | This method moves the current page index to the corresponding page index that is passed as an argument. |
Handling current page changing using event
You can cancel the current page changing operation by handling PageIndexChanging event.
The following example displays the MessageDialog
when end-user tries to change the page.
<datapager:SfDataPager x:Name="sfDataPager"
PageSize="5"
NumericButtonCount="5"
PageCount="10"
PageIndexChanging="sfDataPager_PageIndexChanging"
UseOnDemandPaging="True"/>
this.sfDataPager.PageIndexChanging += SfDataPager_PageIndexChanging;
private async void sfDataPager_PageIndexChanging(object sender, PageIndexChangingEventArgs args)
{
MessageDialog messageDialog = new MessageDialog("Do you want to change the page?");
messageDialog.Commands.Clear();
messageDialog.Commands.Add(new UICommand { Label = "Yes", Id = 0 });
messageDialog.Commands.Add(new UICommand { Label = "No", Id = 1 });
var result = await messageDialog.ShowAsync();
if ((int)result.Id == 1 )
{
args.Cancel = true;
}
}