When retrieving data with specified item amounts and offsets, a display issue occurs on the second page and subsequent pages.
For instance, on the first page, the data correctly shows the first 10 items. However, when using pagination to access the next set of items, only a different number of items is returned, despite the data fetched containing 10 items in the array:
https://codesandbox.io/s/listing-pokemon-on-datagrid-76w3v5
Fetching function:
const fetchPokemon = async (limit, offset) => {
const response = await fetch(
`https://pokeapi.co/api/v2/pokemon?limit=${limit}&offset=${offset}`
);
const data = await response.json();
// this returns 10 items
console.log(data);
const returnedValues = {
results: data.results,
count: data.count
};
return returnedValues;
};
DataGrid component:
<DataGrid
autoHeight
columns={cols}
loading={dataGridState.loading}
rowCount={dataGridState.amount}
rows={pokemon}
pagination={{
pageSize: dataGridState.pageSize,
page: dataGridState.offset - 1
}}
pageSize={dataGridState.pageSize}
onPageChange={handlePageSize}
onPaginationModelChange={async (val) => handlePageSize(val)}
/>