-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use UTable with paginated data, which comes from API #3776
Comments
Hi, here's a component that I wrote to manage pagination (I also use a Laravel API as backend). <script lang="ts" setup>
import type { Meta } from '~/types'
const props = defineProps<{
meta: Meta
}>()
const page = defineModel('page', {
type: Number,
default: () => 1
})
</script>
<template>
<div class="w-full flex items-center justify-between py-3.5">
<UPagination
v-model:page="page"
size="sm"
:items-per-page="props.meta.per_page ?? 1"
:total="props.meta.total ?? 0"
/>
<UBadge :label="`${props.meta.total ?? 0} enregistrement${props.meta.total === 0 ? '' : 's'}`" />
</div>
</template>
On my pages, I use my pagination component like that <AppTablePagination
:objects="records?.data.data ?? []"
:meta="records.data.meta"
:page="page"
@update:page="(event: number) => {
page = event
router.push({ query: { ...route.query, page: event }, replace: true })
refresh()
}"
/> Hope it could help you |
Thanks! I will try that. Bc I am on mobile at the moment, please excuse that I cannot test it just now. One question remains: On the actual table, you are not using v-model:pagination and the pagination-options at all, right? |
I got a first working example based on docs and your example. In the table's component:
This exposes the table ref, which I can use in a different component like this:
This might not be the final version, but it is working for now. Thanks a lot for your helpful example. |
Description
Hi there,
I'd like to know, how to deal with paginated data that comes from the used API, e.g. a Laravel resource response.
I am a bit intimidated by the TanStack API.
The text was updated successfully, but these errors were encountered: