fix: pagination

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-06-08 17:11:09 +07:00
parent 5c05df26cf
commit 5ba2a6dce5
3 changed files with 27 additions and 42 deletions

View file

@ -13,20 +13,15 @@ import SkeletonTable from '@/components/SkeletonTable.vue' // skeleton table
const { date2Thai } = useCounterMixin() const { date2Thai } = useCounterMixin()
const stores = useCheckIn() const stores = useCheckIn()
const page = defineModel<number>('page', { required: true })
const pageSize = defineModel<number>('pageSize', { required: true })
/** props ข้อมูลจาก Components Page HistoryView */ /** props ข้อมูลจาก Components Page HistoryView */
const props = defineProps({ const props = defineProps({
paging: { paging: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
pageSize: {
type: Number,
default: 10,
},
page: {
type: Number,
default: 1,
},
maxPage: { maxPage: {
type: Number, type: Number,
default: 1, default: 1,
@ -194,31 +189,20 @@ const visibleColumns = ref<string[]>([
'checkOutLocation', 'checkOutLocation',
'checkOutStatus', 'checkOutStatus',
]) ])
const pagination = ref({
const currentPage = ref<number>(1) // page: page.value,
// Pagination - initial pagination rowsPerPage: pageSize.value,
const initialPagination = ref<Pagination>({
sortBy: null,
descending: false,
page: 1,
rowsPerPage: props.pageSize, // set page
}) })
// Pagination - update rowsPerPage // Pagination - update rowsPerPage
async function updatePagination(newPagination: Pagination) { async function updatePagination(newPagination: Pagination) {
initialPagination.value = newPagination pageSize.value = newPagination.rowsPerPage
currentPage.value = 1 // set current page 1 per row
} }
async function filterFn() { async function filterFn() {
// 'update:change-page' emit('update:change-page', 1, pageSize.value, keyword.value)
emit(
'update:change-page',
1,
initialPagination.value.rowsPerPage,
keyword.value
)
} }
const modalPopup = ref<boolean>(false) // popup const modalPopup = ref<boolean>(false) // popup
const titlePopup = ref<string>('') // popup const titlePopup = ref<string>('') // popup
const dataRow = ref<DataCheckIn>() // const dataRow = ref<DataCheckIn>() //
@ -276,17 +260,15 @@ function onClickOpenPopupRejrct(data: DataCheckIn) {
} }
} }
/** watch currentPage และ rowsPerPage*/ function onUpdatePage(val: number) {
emit('update:change-page', val, pageSize.value, keyword.value)
}
/** watch pageSize*/
watch( watch(
[() => currentPage.value, () => initialPagination.value.rowsPerPage], () => pageSize.value,
() => { () => {
// 'update:change-page' emit('update:change-page', 1, pageSize.value, keyword.value)
emit(
'update:change-page',
currentPage.value,
initialPagination.value.rowsPerPage,
keyword.value
)
} }
) )
</script> </script>
@ -340,10 +322,10 @@ watch(
v-model:selected="selected" v-model:selected="selected"
:virtual-scroll-sticky-size-start="48" :virtual-scroll-sticky-size-start="48"
:style="$q.screen.gt.xs ? 'max-height: 64vh' : ''" :style="$q.screen.gt.xs ? 'max-height: 64vh' : ''"
:rows-per-page-options="[10, 25, 50, 100]" :rows-per-page-options="[1, 10, 25, 50, 100]"
:grid="$q.screen.gt.xs ? false : true" :grid="$q.screen.gt.xs ? false : true"
:pagination="initialPagination"
@update:pagination="updatePagination" @update:pagination="updatePagination"
v-model:pagination="pagination"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -476,10 +458,11 @@ watch(
</q-card> </q-card>
</div> </div>
</template> </template>
<template v-slot:pagination> <template v-slot:pagination>
งหมด {{ props.total }} รายการ งหมด {{ props.total }} รายการ
<q-pagination <q-pagination
v-model="currentPage" v-model="page"
active-color="primary" active-color="primary"
color="dark" color="dark"
:max-pages="5" :max-pages="5"
@ -487,6 +470,7 @@ watch(
boundary-links boundary-links
direction-links direction-links
:max="Number(props.maxPage)" :max="Number(props.maxPage)"
@update:model-value="onUpdatePage"
></q-pagination> ></q-pagination>
</template> </template>
</q-table> </q-table>

View file

@ -29,7 +29,7 @@ interface Pagination {
sortBy: string | null sortBy: string | null
descending: boolean descending: boolean
page: number page: number
rowsPerPage: number | undefined rowsPerPage: number
} }
interface DataCheckIn { interface DataCheckIn {
checkInDate: string checkInDate: string

View file

@ -115,6 +115,7 @@ async function fetchlistTime() {
async function updateYear(y: number, m: number) { async function updateYear(y: number, m: number) {
stores.tab === 'history' ? (year.value = y) : (year2.value = y) stores.tab === 'history' ? (year.value = y) : (year2.value = y)
month.value = m month.value = m
page.value = 1 //
await functionFetch() // functionFetch await functionFetch() // functionFetch
} }
@ -177,9 +178,9 @@ watch(
/> />
<TableHistory <TableHistory
:fetch-data="functionFetch" :fetch-data="functionFetch"
:page-size="pageSize" v-model:page-size="pageSize"
:total="total" :total="total"
:page="page" v-model:page="page"
:paging="true" :paging="true"
@update:change-page="changePage" @update:change-page="changePage"
:max-page="maxPage" :max-page="maxPage"
@ -196,9 +197,9 @@ watch(
/> />
<TableHistory <TableHistory
:fetch-data="functionFetch" :fetch-data="functionFetch"
:page-size="pageSize" v-model:page-size="pageSize"
:total="total" :total="total"
:page="page" v-model:page="page"
:paging="true" :paging="true"
@update:change-page="changePage" @update:change-page="changePage"
:max-page="maxPage" :max-page="maxPage"