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:
parent
587d7396b3
commit
3f166285de
|
@ -191,6 +191,7 @@ impl<'a> Paginator<'a> {
|
||||||
);
|
);
|
||||||
paginator.insert("pages", to_value(¤t_pager.pages).unwrap());
|
paginator.insert("pages", to_value(¤t_pager.pages).unwrap());
|
||||||
paginator.insert("current_index", to_value(current_pager.index).unwrap());
|
paginator.insert("current_index", to_value(current_pager.index).unwrap());
|
||||||
|
paginator.insert("total_pages", to_value(self.all_pages.len()).unwrap());
|
||||||
|
|
||||||
paginator
|
paginator
|
||||||
}
|
}
|
||||||
|
@ -323,6 +324,7 @@ mod tests {
|
||||||
assert_eq!(context["next"], to_value::<Option<()>>(None).unwrap());
|
assert_eq!(context["next"], to_value::<Option<()>>(None).unwrap());
|
||||||
assert_eq!(context["previous"], to_value("https://vincent.is/posts/").unwrap());
|
assert_eq!(context["previous"], to_value("https://vincent.is/posts/").unwrap());
|
||||||
assert_eq!(context["current_index"], to_value(2).unwrap());
|
assert_eq!(context["current_index"], to_value(2).unwrap());
|
||||||
|
assert_eq!(context["total_pages"], to_value(4).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -28,6 +28,8 @@ next: String?;
|
||||||
pages: Array<Page>;
|
pages: Array<Page>;
|
||||||
// Which pager are we on
|
// Which pager are we on
|
||||||
current_index: Number;
|
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
|
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
|
||||||
|
|
Loading…
Reference in a new issue