From 807bc9911ce23bd1deb69b0a0d61ac9c7a632b55 Mon Sep 17 00:00:00 2001 From: Geovanni Perez <1775792+geoperez@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:03:44 -0600 Subject: [PATCH] Update --- sample/index.tsx | 6 +++--- src/Table/index.tsx | 10 +++++----- src/constants.ts | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sample/index.tsx b/sample/index.tsx index 847ebca..0bfd61a 100644 --- a/sample/index.tsx +++ b/sample/index.tsx @@ -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) => - ( - {rawData && {String(data)}} + label: 'Title', render: (column, { columnIndex, rowIndex }, data, rawData) => + ( + {rawData && {String(data)}} ) }, diff --git a/src/Table/index.tsx b/src/Table/index.tsx index 8c9f2d8..41b4bd9 100644 --- a/src/Table/index.tsx +++ b/src/Table/index.tsx @@ -117,14 +117,14 @@ const TableFooter = ({ footer, columns }: TableFooterProps) => ( ); const getRows = (data: TableCellTypes[][], columns: TableColumn[], rawData: TDataIn) => - data.map((row) => ( + data.map((row, rowIndex) => ( - {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) ) : ( - - + + ), )} diff --git a/src/constants.ts b/src/constants.ts index ae62a15..21354a0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -40,6 +40,11 @@ export type ChartComponent = DataComponent export type TableCellTypes = string | number | Array | Date | boolean | null | undefined; +export type TableCoordinate = { + rowIndex: number; + columnIndex: number; +}; + export type TableColumn = { label: string; dataType?: DataTypes; @@ -50,7 +55,7 @@ export type TableColumn = { textAlign?: TextAlign; render?: ( column: TableColumn, - index: number, + coordinate: TableCoordinate, cellValue: TableCellTypes, rawData: TDataIn, data: TableCellTypes[][],