What would be the best way to handle paginations and filtering
What would be the best way to handle backend pagination and filtering with db?
I am looking for suggestions, still can fully wrap my head around it. We would fetch every page and filter individualy and then push those records to a collection?
8 Replies
continuing-cyan•2mo ago
generally you want to filter/paginate with a query — so overfetch to the collection and pull out what you need through the query
flat-fuchsiaOP•2mo ago
Thanks for answering and sorry for the delay.
What do you mean by overfetch the collection?
afraid-scarlet•2mo ago
i think for example you have a main collection like
todoCollection
and use a paginated live query using the query buildercontinuing-cyan•2mo ago
you show 25 items / page so your collection grabs 150 items & then your db query does the order & limit & offset
flat-fuchsiaOP•2mo ago
But I don’t think that does not properly solves it.
A solution like this forces you to have 2 sets of paginations, db / collections. Your query always fetches more than the collection will show. Is a simple strategy. If I am not mistaken
I was thinking something that unifies the pagination/order/filtering using only the collections query. When you do a query to the live query this also syncs pulls the backend data to the collection.
So for big paginated data, the collection is not local first, but works mostly as a cache.
continuing-cyan•2mo ago
haha yes, agreed! I should have linked to this as well — https://github.com/TanStack/db/issues/343
What I'm describing is the workaround right now
GitHub
Paginated / Infinite Collections · Issue #343 · TanStack/db
A common request we are receiving is to lazily load data into a "query collection" using the infinite query pattern. We need to consider how to support this in a way that is then useable ...
flat-fuchsiaOP•2mo ago
Haha thanks!! Ill take a look at that
@Kyle Mathews i read this, sounds interesting. But something that I dont see considered or I am missing something is What would happen when you have server side filtering. There, we can get items twice for different filters. Saving them in the collection might require extra logic to maintain consistency
Is there a way I can contribute on this tipic, I think is quite an important detail, and most of the approaches I’ve look or different tools out there, offer simplistic solutions to the topic.
Also I am free to jump on calls or whatever. I really want to add tanstack db into our project. Because I think is THE solution for us.
continuing-cyan•2mo ago
the best way to contribute to the topic at this point is to write up a detailed report on how your app works in the above discussions and what you'd need for it to work!