From d7682b47ba495cfa85dae5faafe2497a4685f0f4 Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Thu, 20 Feb 2025 13:45:10 +0700 Subject: [PATCH] feat: add error handling to onCount function and ensure local count is set correctly --- components/tablelist/TableList.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/components/tablelist/TableList.tsx b/components/tablelist/TableList.tsx index 39b2e67..1640bf7 100644 --- a/components/tablelist/TableList.tsx +++ b/components/tablelist/TableList.tsx @@ -238,11 +238,13 @@ export const TableList: React.FC = ({ {"Loading..."} ); - if (typeof onCount === "function") { - const res = await onCount(); - local.count = res; - local.render(); - } + try { + if (typeof onCount === "function") { + const res = await onCount(); + local.count = res; + local.render(); + } + } catch (ex) {} if (mode === "form") { local.data = fm.data?.[name] || []; cloneListFM(fm.data?.[name] || []); @@ -264,6 +266,9 @@ export const TableList: React.FC = ({ if (!autoPagination) { res = paginateArray(res, take, 1); } + if (!local.count) { + local.count = res?.length; + } local.data = res; if (mode === "form") cloneListFM(res); local.render();