ปรับ paging ประวัติการลงเวลา

This commit is contained in:
Warunee Tamkoo 2023-11-22 16:15:12 +07:00
parent 21e1016cae
commit 5cca23b11d
2 changed files with 30 additions and 17 deletions

View file

@ -77,25 +77,34 @@ const props = defineProps({
}, },
}) })
// Pagination - page & change page & get new data const emit = defineEmits(['update:change-page'])
const currentPage = ref<number>(1)
watch(currentPage, () => {
console.log(currentPage.value)
props.changePage(currentPage.value, props.pageSize, true)
})
// Pagination - initial pagination // Pagination - initial pagination
const initialPagination = ref<any>({ const initialPagination = ref<any>({
sortBy: null, sortBy: null,
descending: false, descending: false,
page: 1, page: 1,
rowsPerPage: 1, rowsPerPage: props.pageSize, // set page
}) })
// Pagination - page & change page & get new data
const currentPage = ref<number>(1)
watch(
[() => currentPage.value, () => initialPagination.value.rowsPerPage],
() => {
emit(
'update:change-page',
currentPage.value,
initialPagination.value.rowsPerPage,
true
)
}
)
// Pagination - update rowsPerPage // Pagination - update rowsPerPage
async function updatePagination(newPagination: any) { async function updatePagination(newPagination: any) {
props.changePage(1, newPagination.rowsPerPage, true)
initialPagination.value = newPagination initialPagination.value = newPagination
currentPage.value = 1 // set current page 1 per row
} }
/** column history table */ /** column history table */

View file

@ -18,15 +18,15 @@ const { fetchHistoryList } = stores
const $q = useQuasar() // noti quasar const $q = useQuasar() // noti quasar
onMounted(() => { onMounted(() => {
// fetchlistHistory() fetchlistHistory()
}) })
// paging // paging
const page = ref<number>(1) const page = ref<number>(1)
const year = ref<number>(2023) const year = ref<number>(2023)
const pageSize = ref<number>(5) const pageSize = ref<number>(2)
const total = ref<number>(0) const total = ref<number>(0)
const maxPage = ref<number>(5) const maxPage = ref<number>(1)
const filter = ref<string>('') //search data table const filter = ref<string>('') //search data table
/** /**
@ -45,7 +45,10 @@ async function changePage(
fetchlistHistory(loading) fetchlistHistory(loading)
} }
// /**
* งกนดงขอมลรายการประวการลงเวลาจาก api มาแสดง
* @param loading แสดง loading ไหม true อแสดง, false อไมแสดง
*/
const fetchlistHistory = async (loading = true) => { const fetchlistHistory = async (loading = true) => {
loading === true ?? showLoader() loading === true ?? showLoader()
await http await http
@ -55,9 +58,11 @@ const fetchlistHistory = async (loading = true) => {
) )
.then(async (res) => { .then(async (res) => {
const data = res.data.result const data = res.data.result
total.value = data.total total.value = data.total ? data.total : 5
// maxPage.value = await Math.ceil(data.total / pageSize.value) maxPage.value = await Math.ceil(total.value / pageSize.value)
fetchHistoryList(data) maxPage.value = maxPage.value < 1 ? 1 : maxPage.value
fetchHistoryList(data) // total
// fetchHistoryList(data.data) // total
}) })
.catch((err) => { .catch((err) => {
messageError($q, err) messageError($q, err)
@ -65,7 +70,6 @@ const fetchlistHistory = async (loading = true) => {
.finally(() => { .finally(() => {
hideLoader() hideLoader()
}) })
console.log(maxPage.value)
} }
</script> </script>
<template> <template>
@ -98,7 +102,7 @@ const fetchlistHistory = async (loading = true) => {
:total="total" :total="total"
:page="page" :page="page"
:paging="true" :paging="true"
:changePage="changePage" @update:change-page="changePage"
:max-page="maxPage" :max-page="maxPage"
/> />
</div> </div>