-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,183 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Backend Methods | ||
order: 100 | ||
--- | ||
|
||
Include this module in your controller to have the methods to paginate your collections: | ||
|
||
```ruby ApplicationController | ||
include Pagy::Backend | ||
``` | ||
|
||
!!!success Pagy loads ONLY the methods that you actually use | ||
|
||
The rest of the pagy code will never use any memory | ||
!!! | ||
|
||
!!!warning Don't instantiate any Pagy class directly | ||
|
||
Use the paginator methods that know which implementer class to use, and how to initialize it. | ||
!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: pagy_extract_hash | ||
order: 100 | ||
--- | ||
|
||
`pagy_extract_hash` extracts a hash of the key/values that you pluck from the pagy object. It is useful to export the pagination | ||
data to Javascript frameworks like Vue.js, react.js, etc. | ||
|
||
```ruby Controller (action) | ||
@pagy, @records = pagy_offset(collection, **options) | ||
pagy_hash = pagy_extract_hash(@pagy, pluck_keys: %i[page previous next previous_url next_url ...]) | ||
#=> { page: 3, previous: 2, next: 4, previous_url: ... } | ||
render json: { data: @records, pagy: pagy_hash } | ||
``` | ||
|
||
==- Options | ||
|
||
- `pluck_keys` | ||
|
||
- For efficiency reasons you should always set the `:pluck_keys` option t restrict the output to ONLY the keys that you use. | ||
Notice that you can also add other pagy method names not included in the default below: | ||
|
||
- count | ||
- first_url | ||
- from | ||
- in | ||
- last | ||
- last_url | ||
- limit | ||
- next | ||
- next_url | ||
- options | ||
- page | ||
- page_url | ||
- pages | ||
- previous | ||
- previous_url | ||
- sequels | ||
- series | ||
- to | ||
- url_template | ||
|
||
==- Usage of `:url_template` | ||
|
||
This is a URL string containing the `"P "` page token in place of the page value. | ||
|
||
For example: `'/foo?page=P &bar=baz'`). | ||
|
||
You can replace with Javascript to create th actual page URLs: | ||
|
||
```js | ||
pageUrl = url_template.replace("P ", pageValue) | ||
``` | ||
|
||
!!!warning You may not need it for simple cases! | ||
|
||
Consider to use the few `:*_url` pluck_keys directly, instead of using the `:url_template`. | ||
!!! | ||
|
||
=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: pagy_links_hash | ||
--- | ||
|
||
`pagy_links_hash` returns the `:first`, `:previous`, `:next`, `:last` non`nil` URLs hash. | ||
|
||
It respects `jsonapi: true` if passed with `@pagy`. | ||
|
||
```ruby Controller | ||
link_hash = pagy_links_hash(@pagy, **options) | ||
``` | ||
|
||
=== Options | ||
|
||
- `absolute: true` | ||
- URL absolute | ||
- `fragment: '#...'` | ||
- URL fragment string | ||
|
||
=== |
Oops, something went wrong.