Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Dec 27, 2023
1 parent dd07dd2 commit 807bc99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions sample/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ const onlineColumns: TableColumn[] = [
{ label: 'User Id' },
{ label: 'Id', sortOrder: 1, sortDirection: 'asc', dataType: 'number' },
{
label: 'Title', render: (column, index, data, rawData) =>
(<TableCell column={column} index={index} className='bg-gray-100'>
{rawData && <a href={`https://jsonplaceholder.typicode.com/posts/${rawData[index].id}`}>{String(data)}</a>}
label: 'Title', render: (column, { columnIndex, rowIndex }, data, rawData) =>
(<TableCell column={column} index={columnIndex} className='bg-gray-100'>
{rawData && <a href={`https://jsonplaceholder.typicode.com/posts/${rawData[rowIndex].id}`}>{String(data)}</a>}
</TableCell>
)
},
Expand Down
10 changes: 5 additions & 5 deletions src/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ const TableFooter = ({ footer, columns }: TableFooterProps) => (
);

const getRows = <TDataIn,>(data: TableCellTypes[][], columns: TableColumn[], rawData: TDataIn) =>
data.map((row) => (
data.map((row, rowIndex) => (
<TableRow key={objectHash(row)}>
{columns.map((column, index) =>
{columns.map((column, columnIndex) =>
column.render ? (
column.render(column, index, row[index], rawData, data)
column.render(column, { rowIndex, columnIndex }, row[columnIndex], rawData, data)
) : (
<TableCell key={column.label} column={column} index={index}>
<TableCellContent data={row[index]} column={column} />
<TableCell key={column.label} column={column} index={columnIndex}>
<TableCellContent data={row[columnIndex]} column={column} />
</TableCell>
),
)}
Expand Down
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export type ChartComponent<TDataIn, TDataOut> = DataComponent<TDataIn, TDataOut>

export type TableCellTypes = string | number | Array<string> | Date | boolean | null | undefined;

export type TableCoordinate = {
rowIndex: number;
columnIndex: number;
};

export type TableColumn = {
label: string;
dataType?: DataTypes;
Expand All @@ -50,7 +55,7 @@ export type TableColumn = {
textAlign?: TextAlign;
render?: <TDataIn>(
column: TableColumn,
index: number,
coordinate: TableCoordinate,
cellValue: TableCellTypes,
rawData: TDataIn,
data: TableCellTypes[][],
Expand Down

0 comments on commit 807bc99

Please sign in to comment.