From ff12b7556b7f71a5ec5a4ad466879aaa4cb118fc Mon Sep 17 00:00:00 2001 From: Geriano Date: Fri, 29 Jul 2022 17:19:25 +0700 Subject: [PATCH] create pagination link --- resources/js/Components/DataTable/Builder.vue | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/resources/js/Components/DataTable/Builder.vue b/resources/js/Components/DataTable/Builder.vue index ea2e2e1..e5f72b6 100644 --- a/resources/js/Components/DataTable/Builder.vue +++ b/resources/js/Components/DataTable/Builder.vue @@ -2,7 +2,7 @@ import { useForm } from '@inertiajs/inertia-vue3' import axios from 'axios' import Swal from 'sweetalert2' -import { getCurrentInstance, onMounted, ref } from 'vue' +import { getCurrentInstance, onMounted, onUpdated, ref } from 'vue' const self = getCurrentInstance() const { url, sticky } = defineProps({ @@ -26,6 +26,15 @@ const config = useForm({ sticky, }) +const goTo = link => { + if (!link.url) { + return + } + + config.page = Number(link.url.match(/page=([\d]+)/)[1]) + paginator.value.current_page !== config.page && fetch() +} + const fetch = async u => { try { const a = last.value = u || url @@ -74,9 +83,17 @@ const createFloatingTh = () => { } } -onMounted(fetch) +const rounded = () => { + const { links } = self.refs + links && links.firstElementChild?.classList.add('rounded-l-md') + links && links.lastElementChild?.classList.add('rounded-r-md') +} + +onMounted(fetch) onMounted(() => config.sticky && createFloatingTh()) +onMounted(() => rounded()) +onUpdated(() => rounded()) \ No newline at end of file