apply<T extends DataGridRow> method
Apply this event's transformation to the state. Returns the new state, or null if no state change should occur. Can return a Future for async operations.
Implementation
@override
DataGridState<T>? apply<T extends DataGridRow>(EventContext<T> context) {
final currentContextState = context.state;
final paginationState = currentContextState.pagination;
if (!paginationState.enabled) return null;
if (pageSize <= 0) return null;
final newPagination = paginationState.copyWith(pageSize: pageSize);
final totalPages = newPagination.totalPages(currentContextState.totalItems);
final currentPage = math.min(paginationState.currentPage, totalPages);
final adjustedPagination = newPagination.copyWith(currentPage: currentPage);
final List<double> newDisplayOrder;
if (paginationState.serverSide) {
newDisplayOrder = currentContextState.displayOrder;
} else {
final startIndex = adjustedPagination.startIndex(
currentContextState.totalItems,
);
final endIndex = adjustedPagination.endIndex(
currentContextState.totalItems,
);
final allIds = currentContextState.rowsById.keys.toList();
newDisplayOrder = allIds.sublist(
math.min(startIndex, allIds.length),
math.min(endIndex, allIds.length),
);
}
return currentContextState.copyWith(
pagination: adjustedPagination,
displayOrder: newDisplayOrder,
);
}