From 6606790f35cc755538d6ac31821757d04ea5e799 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 27 Dec 2023 10:39:58 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20filter=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=84=E0=B8=B3=E0=B8=82=E0=B8=AD=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B9=80=E0=B8=A1=E0=B8=B4=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../12_evaluatePersonal/views/MainPage.vue | 87 ++++++++++++------- 1 file changed, 56 insertions(+), 31 deletions(-) diff --git a/src/modules/12_evaluatePersonal/views/MainPage.vue b/src/modules/12_evaluatePersonal/views/MainPage.vue index 927cc17b5..d28f942b3 100644 --- a/src/modules/12_evaluatePersonal/views/MainPage.vue +++ b/src/modules/12_evaluatePersonal/views/MainPage.vue @@ -17,74 +17,94 @@ const mixin = useCounterMixin(); const store = useEvalutuonStore(); const { showLoader, hideLoader, messageError } = mixin; const attrs = ref(useAttrs()); -const initialPagination = ref({ - rowsPerPage: 0, -}); + function Detailpage(id: string) { router.push(`/evaluate/detail/${id}`); } const currentPage = ref(1); -const maxPage = ref(1); +const maxPage = ref(0); const page = ref(1); const total = ref(0); const filter = ref(""); -const rowsPerPage = ref(10); +const pageSize = ref(10); + /** *pagination ของตาราง */ -const pagination = ref({ +const initialPagination = ref({ + sortBy: null, descending: false, - page: page.value, - rowsPerPage: rowsPerPage.value, + page: 1, + rowsPerPage: pageSize, }); // Pagination - update rowsPerPage async function updatePagination(initialPagination: any) { currentPage.value = 1; - rowsPerPage.value = initialPagination.rowsPerPage; + pageSize.value = initialPagination.rowsPerPage; page.value = 1; // set current page เป็น 1 เสมอเมื่อเปลี่ยน per row } - +// Pagination - page & change page & get new data watch( - () => currentPage.value, - () => { - rowsPerPage.value = pagination.value.rowsPerPage; + [ + () => currentPage.value, + () => (pageSize.value = initialPagination.value.rowsPerPage), + ], + async () => { getList(); } ); - +// Pagination - page & change page & get new data watch( - () => pagination.value.rowsPerPage, + [() => currentPage.value, () => initialPagination.value.rowsPerPage], + async () => { + page.value = currentPage.value; + await getList(); + } +); +watch( + () => initialPagination.value.rowsPerPage, () => { - rowsPerPage.value = pagination.value.rowsPerPage; + pageSize.value = initialPagination.value.rowsPerPage; currentPage.value = 1; getList(); } ); +/** + * filter function + */ +const filterRef = ref(null); function filterFn() { + updatePagination(filter.value); + pageSize.value = initialPagination.value.rowsPerPage; getList(); } +const resetFilter = () => { + filter.value = ""; + getList(); + if (filterRef.value) { + filterRef.value.focus(); + } +}; + function getList() { showLoader(); http .get( - config.API.evaluationMain( - currentPage.value, - rowsPerPage.value, - filter.value - ) + config.API.evaluationMain(currentPage.value, pageSize.value, filter.value) ) .then(async (res) => { + const data = res.data.result.data; total.value = res.data.result.total; - maxPage.value = await Math.ceil(total.value / rowsPerPage.value); - maxPage.value = maxPage.value < 1 ? 1 : maxPage.value; console.log(res.data.result.total); - console.log(rowsPerPage.value); + maxPage.value = await Math.ceil(total.value / pageSize.value); + maxPage.value = maxPage.value < 1 ? 1 : maxPage.value; + console.log(total.value); + console.log(pageSize.value); console.log(maxPage.value); - const data = res.data.result.data; store.fetchData(data); }) .catch((e) => { @@ -122,7 +142,13 @@ onMounted(async () => { @keydown.enter.prevent="filterFn" > @@ -148,16 +174,15 @@ onMounted(async () => { ref="table" :columns="store.columns" :rows="store.rows" - :filter="filter" row-key="interrogated" flat bordered - :paging="true" + :paging="false" dense class="custom-header-table" :visible-columns="store.visibleColumns" - v-model:pagination="pagination" - :rows-per-page-options="[10, 25, 50, 100]" + v-model:pagination="initialPagination" + :rows-per-page-options="[2, 25, 50, 100]" @update:pagination="updatePagination" >