feat: add error handling to onCount function and ensure local count is set correctly

This commit is contained in:
faisolavolut 2025-02-20 13:45:10 +07:00
parent 09fc4af459
commit d7682b47ba
1 changed files with 10 additions and 5 deletions

View File

@ -238,11 +238,13 @@ export const TableList: React.FC<any> = ({
{"Loading..."} {"Loading..."}
</> </>
); );
if (typeof onCount === "function") { try {
const res = await onCount(); if (typeof onCount === "function") {
local.count = res; const res = await onCount();
local.render(); local.count = res;
} local.render();
}
} catch (ex) {}
if (mode === "form") { if (mode === "form") {
local.data = fm.data?.[name] || []; local.data = fm.data?.[name] || [];
cloneListFM(fm.data?.[name] || []); cloneListFM(fm.data?.[name] || []);
@ -264,6 +266,9 @@ export const TableList: React.FC<any> = ({
if (!autoPagination) { if (!autoPagination) {
res = paginateArray(res, take, 1); res = paginateArray(res, take, 1);
} }
if (!local.count) {
local.count = res?.length;
}
local.data = res; local.data = res;
if (mode === "form") cloneListFM(res); if (mode === "form") cloneListFM(res);
local.render(); local.render();