Paginators
Svelte ComponentNavigate between multiple pages of content.
Import
Package
Source
Docs
Examples
Positions | Name | Weight | Symbol |
---|---|---|---|
1 | Hydrogen | 1.0079 | H |
2 | Helium | 4.0026 | He |
3 | Lithium | 6.941 | Li |
4 | Beryllium | 9.0122 | Be |
5 | Boron | 10.811 | B |
1 to 5 of 10
Usage
const page: any = {
offset: 0,
limit: 5,
size: source.length,
amounts: [1,2,5,10],
};
<Paginator
bind:offset={page.offset}
bind:limit={page.limit}
bind:size={page.size}
bind:amounts={page.amounts}
on:page={onPageChange}
on:amount={onAmountChange}
></Paginator>
Utilizing Pagination
Once your paginator component is setup you'll need to limit your content. This can be accomplished with the JavaScript slice method. See a minimal example below.
const source: any[] = [ /* any array of objects */ ]
$: sourcePaginated = source.slice(
page.offset * page.limit, // start
page.offset * page.limit + page.limit // end
);
<ul>
{#each sourcePaginated as row}
<li>{row}</li>
{/each}
</ul>