From 36c71e3fda2e7ef55cc0e24672c194c14fc5f303 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 7 Jul 2025 18:07:54 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20Function=20updateCurrentPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/function.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/utils/function.ts diff --git a/src/utils/function.ts b/src/utils/function.ts new file mode 100644 index 000000000..82896079a --- /dev/null +++ b/src/utils/function.ts @@ -0,0 +1,19 @@ +/** + * คำนวณหน้าที่ควรแสดงหลังจากลบข้อมูล + * + * @param page หน้าปัจจุบัน + * @param maxPage หน้าสุดท้าย + * @param currentPageItems จำนวนข้อมูลในหน้าปัจจุบัน + * @returns หน้าที่ควรแสดง + */ +export function updateCurrentPage( + page: number, + maxPage: number, + total: number +) { + // ถ้าหน้าปัจจุบันไม่ใช่หน้าแรก และเป็นหน้าสุดท้าย และมีข้อมูลเหลือ 1 รายการ ให้กลับไปหน้าก่อนหน้า + if (page > 1 && page === maxPage && total === 1) { + return page - 1; + } + return page; +}