mirror of
https://github.com/twentyhq/twenty.git
synced 2026-06-13 18:37:35 -04:00
77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import * as React from 'react';
|
|
|
|
import {
|
|
ColumnDef,
|
|
flexRender,
|
|
getCoreRowModel,
|
|
useReactTable,
|
|
} from '@tanstack/react-table';
|
|
import TableHeader from './TableHeader';
|
|
|
|
type OwnProps = {
|
|
data: Array<any>;
|
|
columns: Array<ColumnDef<any, any>>;
|
|
viewName: string;
|
|
};
|
|
|
|
function Table({ data, columns, viewName }: OwnProps) {
|
|
const table = useReactTable({
|
|
data,
|
|
columns,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
});
|
|
|
|
return (
|
|
<div>
|
|
<TableHeader viewName={viewName} />
|
|
<table>
|
|
<thead>
|
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
<tr key={headerGroup.id}>
|
|
{headerGroup.headers.map((header) => (
|
|
<th key={header.id}>
|
|
{header.isPlaceholder
|
|
? null
|
|
: flexRender(
|
|
header.column.columnDef.header,
|
|
header.getContext(),
|
|
)}
|
|
</th>
|
|
))}
|
|
</tr>
|
|
))}
|
|
</thead>
|
|
<tbody>
|
|
{table.getRowModel().rows.map((row) => (
|
|
<tr key={row.id}>
|
|
{row.getVisibleCells().map((cell) => (
|
|
<td key={cell.id}>
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
</td>
|
|
))}
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
<tfoot>
|
|
{table.getFooterGroups().map((footerGroup) => (
|
|
<tr key={footerGroup.id}>
|
|
{footerGroup.headers.map((header) => (
|
|
<th key={header.id}>
|
|
{header.isPlaceholder
|
|
? null
|
|
: flexRender(
|
|
header.column.columnDef.footer,
|
|
header.getContext(),
|
|
)}
|
|
</th>
|
|
))}
|
|
</tr>
|
|
))}
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default Table;
|