forked from anykeyh/clear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two helpers method for pagination module + write documentation
- Loading branch information
Yacine Petitprez
committed
Jun 24, 2018
1 parent
c1ae30e
commit 888e2bc
Showing
3 changed files
with
68 additions
and
2 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 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,57 @@ | ||
Clear offers methods to manage pagination of your models | ||
|
||
Simply use `paginate` method on your collection query: | ||
|
||
|
||
### Methods used for pagination | ||
|
||
## `paginate` | ||
|
||
Used to start pagination mode for your models | ||
|
||
```crystal | ||
users = User.query.paginate(1, per_page: 25) | ||
``` | ||
|
||
## `per_page` | ||
|
||
Return the number of model per page | ||
|
||
```crystal | ||
users.per_page #25 | ||
``` | ||
|
||
## `current_page` | ||
|
||
Return the current selected page. | ||
|
||
|
||
## `total_pages` | ||
|
||
Return the number of pages | ||
|
||
## `previous_page`, `next_page`, `last_page?`, `first_page?` | ||
|
||
Return the previous, next page or `nil` if current page is the first page. | ||
Return `true` or `false` whether the current page is the first or the last. | ||
|
||
|
||
## Example | ||
|
||
```ecr | ||
<div class='my-table'> | ||
<% @users.each do |u| %> | ||
<#...> | ||
<% end %> | ||
<!-- Add pagination widget --> | ||
<% unless @users.first_page? %> | ||
<a href="...?page=<%[email protected]_page%>">Previous</a> | ||
<% end %> | ||
<% unless @users.last_page? %> | ||
<a href="...?page=<%[email protected]_page%>">Next</a> | ||
<a href="...?page=<%[email protected]_pages%>">Last</a> | ||
<% end %> | ||
</div> | ||
``` | ||
|
||
|
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