Skip to content

Looking for example of DataTable to use paginated API #1903

Answered by theetrain
ChristianRiesen asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ChristianRiesen,

In order to paginate results loaded server-side, here's what needs to be done:

  1. Use on:change instead of bind: in <Pagination /> to respond to events such as the user clicking on the 'next page' button.
  2. Do not use <DataTable>'s page prop since that will paginate items already available in the table. In your case, there's only ever one page in the DataTable, but multiple pages represented in <Pagination>.
  3. Make your API call or navigate the page if using SvelteKit's load method
  4. When you reassign your rows and page values, your Pagination and DataTables will update.

Example code:

<script>
  import { goto } from '$app/navigation';
  import { DataTable, Pagination } from '…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ChristianRiesen
Comment options

Answer selected by ChristianRiesen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants