Skip to content

Commit

Permalink
add props to prefix row with an index
Browse files Browse the repository at this point in the history
  • Loading branch information
fdelemarre committed Jun 26, 2024
1 parent e1a7ee3 commit 1638f53
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/webapp/components/table/BasicTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ interface BasicTableProps {
[key: TableColumn["name"]]: string | User;
}[];
onChange?: (cell: TableCellData, rowIndex: number, column: TableColumn["name"]) => void;
showRowIndex?: boolean;
}

export const BasicTable: React.FC<BasicTableProps> = React.memo(
({ columns, rows, onChange = () => {} }) => {
({ columns, rows, onChange = () => {}, showRowIndex = false }) => {
const renderCell = (cell: TableCellData, rowIndex: number, { name, type }: TableColumn) => {
if (!cell) {
return "";
Expand All @@ -39,6 +40,7 @@ export const BasicTable: React.FC<BasicTableProps> = React.memo(
<StyledTable>
<TableHead>
<TableRow>
<TableCell />
{columns.map(({ name }) => (
<TableCell key={name}>{_.startCase(name)}</TableCell>
))}
Expand All @@ -47,6 +49,7 @@ export const BasicTable: React.FC<BasicTableProps> = React.memo(
<TableBody>
{rows.map((row, rowIndex) => (
<TableRow key={rowIndex}>
{showRowIndex && <TableCell>{rowIndex + 1}</TableCell>}
{columns.map(column => (
<TableCell key={`${rowIndex}-${column.name}`}>
{renderCell(row[column.name], rowIndex, column)}
Expand Down

0 comments on commit 1638f53

Please sign in to comment.