Hi Tasha,
With the RestDataProvider, it is a large dataset, so I do not want to be passing the whole contents to the client.
So access to "total={allData.length}" is not available.
the pager needs to request from the RestDataProvider a offset and limit, sort order, ascending or descending and possibly criteria.
here is a GET I was thinking of, but the default provider GET only allows {data} and not {data, total}
export async function GET({ url }) {
const offset = Number(url.searchParams.get('offset') || 0);
const limit = Number(url.searchParams.get('limit') || 20);
const q = url.searchParams.get('q')?.trim();
const sortBy = url.searchParams.get('sortBy') ?? 'createdAt';
const sortOrder = (url.searchParams.get('sortOrder') ?? 'DESC').toUpperCase() as 'ASC' | 'DESC';
const persistance = await Persistance.getInstance();
const where = q
? [
{ name: ILike(`%${q}%`) },
{ breed: ILike(`%${q}%`) },
{ animalId: ILike(`%${q}%`) }
]
: undefined;
const [animals, total] = await persistance.animal.findAndCount({
where,
order: { [sortBy]: sortOrder },
skip: offset,
take: limit
});
return json({ data: animals, total });
}
as for setPage() I was thinking
function setPage(ev) {
const { from, to } = ev;
// If we already have all data, just page locally
if (data.length === totalRows) {
pageData = data.slice(from, to);
} else {
// Otherwise, update URL params to trigger server reload
const params = new URLSearchParams(get(page).url.searchParams);
params.set('offset', from.toString());
params.set('limit', (to - from).toString());
// do call to api
}
}
I dont want to re-invent the wheel, so checking if RestDataProvider and Pager can do something like this or advice on how I should be implement this.
Thank you