Browse Source

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`
index-subcmd
Geobert Quach Vincent Prouillet 5 years ago
parent
commit
3f166285de
2 changed files with 4 additions and 0 deletions
  1. +2
    -0
      components/library/src/pagination/mod.rs
  2. +2
    -0
      docs/content/documentation/templates/pagination.md

+ 2
- 0
components/library/src/pagination/mod.rs 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]


+ 2
- 0
docs/content/documentation/templates/pagination.md 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


Loading…
Cancel
Save