Add pagination elements
This commit is contained in:
parent
7c6ba261f8
commit
6773d6d9bc
16
karaokatalog/ui/static/components/pieces/Pagination.js
Normal file
16
karaokatalog/ui/static/components/pieces/Pagination.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import PaginationControls from "./PaginationControls.js"
|
||||||
|
|
||||||
|
const ELEMENTS_PER_PAGE = 25
|
||||||
|
|
||||||
|
export default {
|
||||||
|
view(vnode) {
|
||||||
|
const elements = vnode.attrs.elements.toArray()
|
||||||
|
const totalPages = Math.ceil(elements.length / ELEMENTS_PER_PAGE)
|
||||||
|
|
||||||
|
const startIndex = (this.currentPageIndex || 0) * ELEMENTS_PER_PAGE
|
||||||
|
return [
|
||||||
|
elements.slice(startIndex, startIndex + ELEMENTS_PER_PAGE),
|
||||||
|
m(PaginationControls, { currentPage: (this.currentPageIndex || 0) + 1, totalPages, onPageChange: i => this.currentPageIndex = i - 1 })
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user