Skip to content

Commit 4d5cd1d

Browse files
fix: fixed columns display for inner table
1 parent 44f4992 commit 4d5cd1d

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/DataTable/DataTable.tsx

+24-12
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,28 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
138138
defaultSortColumn,
139139
} = useColumns(columns, onColumnOrderChange, defaultSortFieldId, defaultSortAsc);
140140

141+
// Find index of last freezed column
142+
const index = React.useMemo(
143+
() =>
144+
tableColumns.reduce((i, column) => {
145+
if (column.freeze) {
146+
i += 1;
147+
}
148+
return i;
149+
}, 0),
150+
[tableColumns],
151+
);
152+
153+
const tableColumnsBasedOnTable = React.useMemo(() => {
154+
if (!isInnerTable) {
155+
return tableColumns;
156+
}
157+
return tableColumns.slice(0, index);
158+
}, [index, isInnerTable, tableColumns]);
159+
141160
const freezedColumns = React.useMemo(() => {
142-
// Find index of last freezed column
143-
const index = tableColumns.reduce((i, column) => {
144-
if (column.freeze) {
145-
i += 1;
146-
}
147-
return i;
148-
}, 0);
149161
return tableColumns.slice(0, index);
150-
}, [tableColumns]);
162+
}, [index, tableColumns]);
151163

152164
const [
153165
{
@@ -486,7 +498,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
486498
</>
487499
)}
488500

489-
{tableColumns.map(column => (
501+
{tableColumnsBasedOnTable.map(column => (
490502
<Column
491503
key={column.id}
492504
column={column}
@@ -534,7 +546,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
534546
key={id}
535547
keyField={keyField}
536548
data-row-id={id}
537-
columns={tableColumns}
549+
columns={tableColumnsBasedOnTable}
538550
row={row}
539551
rowCount={sortedData.length}
540552
rowIndex={i}
@@ -585,7 +597,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
585597
</Wrapper>
586598
</ResponsiveWrapper>
587599

588-
{!isInnerTable && freezedColumns.length > 0 && (
600+
{freezedColumns.length > 0 && (
589601
<div
590602
style={{
591603
position: 'absolute',
@@ -610,7 +622,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
610622
</>
611623
)}
612624

613-
{freezedColumns.slice(0, 3).map(column => (
625+
{freezedColumns.map(column => (
614626
<Column
615627
key={column.id}
616628
column={column}

0 commit comments

Comments
 (0)