handlePageChange method
Called when the page is navigated.
Return true, if the navigation should be performed. Otherwise, return false to disable the navigation for specific page index.
Implementation
@override
Future<bool> handlePageChange(int oldPageIndex, int newPageIndex) {
if (effectiveRows.isEmpty || _pageCount == 0) {
_paginatedRows = <DataGridRow>[];
return Future<bool>.value(true);
}
final DataGridConfiguration dataGridConfiguration =
_dataGridStateDetails!();
final int rowsPerPage = dataGridConfiguration.rowsPerPage ??
(effectiveRows.length / _pageCount).ceil();
final int startIndex = newPageIndex * rowsPerPage;
int endIndex = startIndex + rowsPerPage;
/// Need to calculate endIndex for the last page, when the number of rows is
/// lesser than rowsPerPage.
if (endIndex > effectiveRows.length) {
endIndex = effectiveRows.length;
}
/// Get particular range from the sorted collection.
if (startIndex < effectiveRows.length && endIndex <= effectiveRows.length) {
_paginatedRows = effectiveRows.getRange(startIndex, endIndex).toList();
} else {
_paginatedRows = <DataGridRow>[];
}
/// Updates the collection in data pager.
notifyListeners();
return Future<bool>.value(true);
}