Stop showing empty table when there are no records (#790)

This commit is contained in:
akash-codemonk 2020-09-29 16:12:24 +05:30 committed by GitHub
parent 53c616b747
commit 4d9727203b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,6 +95,8 @@ const Table = (props: TableProps) => {
useFlexLayout,
);
if (rows.length === 0 || headerGroups.length === 0) return null;
return (
<StyledTableWrapped
width={200}
@ -126,7 +128,6 @@ const Table = (props: TableProps) => {
))}
</div>
))}
{headerGroups.length === 0 && renderEmptyRows(1, 2)}
<div {...getTableBodyProps()} className="tbody">
{rows.map((row: any, index: number) => {
prepareRow(row);
@ -150,7 +151,6 @@ const Table = (props: TableProps) => {
</div>
);
})}
{rows.length === 0 && renderEmptyRows(1, 2)}
</div>
</div>
</div>
@ -158,38 +158,4 @@ const Table = (props: TableProps) => {
);
};
const renderEmptyRows = (rowCount: number, columns: number) => {
const rows: string[] = new Array(rowCount).fill("");
const tableColumns = new Array(columns).fill("");
return (
<React.Fragment>
{rows.map((row: string, index: number) => {
return (
<div
className="tr"
key={index}
style={{
display: "flex",
flex: "1 0 auto",
}}
>
{tableColumns.map((column: any, colIndex: number) => {
return (
<div
key={colIndex}
className="td"
style={{
boxSizing: "border-box",
flex: "1 0 auto",
}}
/>
);
})}
</div>
);
})}
</React.Fragment>
);
};
export default Table;