Paginator total pages (#829)

* feat(pagination): Add `total_pages` in paginator object

* feat(pagination): Added doc for `total_pages`

* feat(pagination): Added test for `total_pages`
This commit is contained in:
Geobert Quach 2019-10-28 11:55:49 +00:00 committed by Vincent Prouillet
parent 587d7396b3
commit 3f166285de
2 changed files with 4 additions and 0 deletions

View file

@ -191,6 +191,7 @@ impl<'a> Paginator<'a> {
);
paginator.insert("pages", to_value(&current_pager.pages).unwrap());
paginator.insert("current_index", to_value(current_pager.index).unwrap());
paginator.insert("total_pages", to_value(self.all_pages.len()).unwrap());
paginator
}
@ -323,6 +324,7 @@ mod tests {
assert_eq!(context["next"], to_value::<Option<()>>(None).unwrap());
assert_eq!(context["previous"], to_value("https://vincent.is/posts/").unwrap());
assert_eq!(context["current_index"], to_value(2).unwrap());
assert_eq!(context["total_pages"], to_value(4).unwrap());
}
#[test]

View file

@ -28,6 +28,8 @@ next: String?;
pages: Array<Page>;
// Which pager are we on
current_index: Number;
// Total number of pages accross all the pagers
total_pages: Number;
```
A pager is a page of the pagination: if you have 100 pages and are paginating 10 by 10, you will have 10 pagers containing