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 == enabled) return null;
final newPagination = paginationState.copyWith(enabled: enabled);
final List<double> newDisplayOrder;
int totalItems = currentContextState.totalItems;
if (enabled) {
if (paginationState.serverSide) {
newDisplayOrder = currentContextState.displayOrder;
} else {
final allIds = currentContextState.displayOrder;
totalItems = allIds.length;
final startIndex = newPagination.startIndex(totalItems);
final endIndex = newPagination.endIndex(totalItems);
newDisplayOrder = allIds.sublist(
math.min(startIndex, allIds.length),
math.min(endIndex, allIds.length),
);
}
} else {
final allIds = currentContextState.rowsById.keys.toList();
totalItems = allIds.length;
newDisplayOrder = allIds;
}
return currentContextState.copyWith(
pagination: newPagination,
displayOrder: newDisplayOrder,
totalItems: totalItems,
);
}