diff --git a/packages/common/business_components/src/ui/table/index.tsx b/packages/common/business_components/src/ui/table/index.tsx index ae93cd46f..fc0d5adfb 100644 --- a/packages/common/business_components/src/ui/table/index.tsx +++ b/packages/common/business_components/src/ui/table/index.tsx @@ -12,6 +12,7 @@ type UiTableProps = { cellClick : ((index:number|undefined, headId:string)=>void )| undefined; onPageChange: (page: number) => void; className?: string; + resetPageNo?: boolean; } type UiHeadProps = { @@ -20,22 +21,27 @@ type UiHeadProps = { align?: string; } -export function UiTable({ tableData, headlist, pageSize, total, children, headName, cellClick, onPageChange, className = '' }: UiTableProps) { +export function UiTable({ tableData, headlist, pageSize, total, children, headName, cellClick, onPageChange, className = '', resetPageNo = false }: UiTableProps) { const [cur, setCur] = useState(1); const [idx, setIdx] = useState(-1); + + useEffect(() => { + if (resetPageNo) { + setCur(1); + onPageChange(1); + } + }, [onPageChange, resetPageNo]); + const handlePageChange = (page: number) => { setCur(page); onPageChange(page); } - const handleCellClick = (index: number,headId:string )=> { if (cellClick) { cellClick(index,headId); setIdx(index); } - - }; return ( @@ -53,8 +59,8 @@ export function UiTable({ tableData, headlist, pageSize, total, children, headNa } - {tableData?.map((el: { [key: string]: any}, index) => ( - + {tableData?.map((el: { [key: string]: string | number | boolean | object}, index) => ( + {headlist?.map((head) => ( handleCellClick(index, head.id)} key={head.id + index} > - {el[head.id]} + {String(el[head.id] ?? '')} ))}