content icon indicating copy to clipboard operation
content copied to clipboard

enhancements: pagination helpers

Open bloodf opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe

When creating some application with Nuxt-Content, you may find yourself in need of pagination with possible pages. Like https://github.com/vuestorefront/developer.vuestorefront.io

My solution was to create queries to fetch all files in a specific query, with only some tags, to get the total available in the query without the skip.

Describe the solution you'd like

In the query builder, if possible, add a new function, pagination, where it will return the same as skip and limit but with predefined pagination helpers, like returning the object.

type PaginatedResult = {
  data: Result[]
  total: number
  pages: Page[]
  previousPage: number;
  nextPage: number;
  firstPage: number;
  lastPage: number;
}

In this pagination function, we can pass the limit of items and pages to display.

Describe alternatives you've considered

Have two function to fetch basic data like here https://github.com/vuestorefront/developer.vuestorefront.io/blob/main/store/videos/videoList.ts

bloodf avatar Jul 27 '22 17:07 bloodf

+1, now, i have to use queryContent to get the length of all page first, then use limit and skip, but I realize since I already get all pages data, I could just use the array data of all pages combining with Array slice. hope there would be a more concise method like count, return the count of all page for custom pagination component.

YoonTso avatar Jul 29 '22 15:07 YoonTso

i would love to see a feature like this!

luxterful avatar Sep 10 '22 20:09 luxterful

Bump, this would be very useful ! Currently, we need to do a second query to get the total number of post and it's not efficient as the query will become longer and longer over time as we add more articles...

mrleblanc101 avatar Jan 16 '23 19:01 mrleblanc101