Improve table pagination
This commit is contained in:
parent
aab4fd0832
commit
a861b404b2
1 changed files with 29 additions and 13 deletions
|
@ -1,15 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
import { backendUiStore } from "builderStore"
|
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
export let currentPage
|
export let currentPage
|
||||||
export let pageItemCount
|
export let pageItemCount
|
||||||
export let ITEMS_PER_PAGE
|
export let ITEMS_PER_PAGE
|
||||||
|
|
||||||
let numPages = 0
|
let numPages = 0
|
||||||
|
|
||||||
$: numPages = Math.ceil((data?.length ?? 0) / ITEMS_PER_PAGE)
|
$: numPages = Math.ceil((data?.length ?? 0) / ITEMS_PER_PAGE)
|
||||||
$: console.log(numPages)
|
|
||||||
|
|
||||||
const next = () => {
|
const next = () => {
|
||||||
if (currentPage + 1 === numPages) return
|
if (currentPage + 1 === numPages) return
|
||||||
|
@ -28,8 +24,7 @@
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<div class="pagination__buttons">
|
<div class="pagination__buttons">
|
||||||
<button on:click={previous}>Previous</button>
|
<button on:click={previous} disabled={currentPage === 0}><</button>
|
||||||
<button on:click={next}>Next</button>
|
|
||||||
{#each Array(numPages) as _, idx}
|
{#each Array(numPages) as _, idx}
|
||||||
<button
|
<button
|
||||||
class:selected={idx === currentPage}
|
class:selected={idx === currentPage}
|
||||||
|
@ -37,8 +32,19 @@
|
||||||
{idx + 1}
|
{idx + 1}
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
|
<button
|
||||||
|
on:click={next}
|
||||||
|
disabled={currentPage === numPages - 1 || numPages === 0}>
|
||||||
|
>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p>Showing {pageItemCount} of {data.length} entries</p>
|
|
||||||
|
<p>
|
||||||
|
{#if numPages > 1}
|
||||||
|
Showing {ITEMS_PER_PAGE * currentPage + 1} - {ITEMS_PER_PAGE * currentPage + pageItemCount}
|
||||||
|
of {data.length} rows
|
||||||
|
{:else if numPages === 1}Showing all {data.length} row(s){/if}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -52,26 +58,36 @@
|
||||||
|
|
||||||
.pagination__buttons {
|
.pagination__buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
border: 1px solid var(--grey-4);
|
||||||
|
border-radius: var(--border-radius-s);
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pagination__buttons button {
|
.pagination__buttons button {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 10px;
|
padding: var(--spacing-s) var(--spacing-m);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border: 1px solid var(--grey-4);
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
border-right: 1px solid var(--grey-4);
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
border-radius: 3px;
|
|
||||||
min-width: 20px;
|
min-width: 20px;
|
||||||
transition: 0.3s background-color;
|
transition: 0.3s background-color;
|
||||||
}
|
}
|
||||||
|
.pagination__buttons button:last-child {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
.pagination__buttons button:hover {
|
.pagination__buttons button:hover {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: var(--grey-1);
|
background-color: var(--grey-1);
|
||||||
}
|
}
|
||||||
|
.pagination__buttons button.selected {
|
||||||
|
background: var(--grey-2);
|
||||||
|
}
|
||||||
|
|
||||||
.selected {
|
p {
|
||||||
color: var(--blue);
|
font-size: var(--font-size-s);
|
||||||
|
margin: var(--spacing-xl) 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue