paginate icon indicating copy to clipboard operation
paginate copied to clipboard

Feature request: agnostic web pagination

Open daniel-samson opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I want to be able to pass pagination as a json object in a framework agnostic way. So if i am using bootstrap, tailwindcss, with react or vuejs, i can create can reuse their respective pagination components.

Describe the solution you'd like

Example json

{
  "meta": {
    "page": {
      "current-page": 2,
      "per-page": 15,
      "from": 16,
      "to": 30,
      "total": 50,
      "last-page": 4
    }
  },
  "links": {
    "first": "http://localhost/api/v1/posts?page[number]=1&page[size]=15",
    "prev": "http://localhost/api/v1/posts?page[number]=1&page[size]=15",
    "next": "http://localhost/api/v1/posts?page[number]=3&page[size]=15",
    "last": "http://localhost/api/v1/posts?page[number]=4&page[size]=15"
  },
  "data": [...]
}

Example rust

let baseUrl = "http://localhost/api/v1/posts?foo=bar";
let items: Pages = someProcess();
page = pages.toWeb(baseUrl, items);

daniel-samson avatar Apr 11 '22 09:04 daniel-samson

Perhaps we should introduce a new struct ResourcePages and ResourcePage, to collect the items in the data field, and have a toResource call instead of to web. This would return a ResourcePages object, which would have all the fields needed for a front end pagination component. We maybe should include pages property in the meta section, for components that show buttons for the next N pages eg prev 1 2 3 4 next

daniel-samson avatar Apr 11 '22 09:04 daniel-samson