Skip to content

Commit a3d13d5

Browse files
committedAug 8, 2024
fix: only allow freezed columns for non-expandable tables
1 parent cace3e7 commit a3d13d5

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed
 

‎src/DataTable/DataTable.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
123123
footer = defaultProps.footer,
124124
currentSortColumnId = defaultProps.currentSortColumnId,
125125
currentSortDirection = defaultProps.currentSortDirection,
126-
// isInnerTable = defaultProps.isInnerTable,
126+
isInnerTable = defaultProps.isInnerTable,
127127
} = props;
128128

129129
const {
@@ -139,16 +139,16 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
139139
} = useColumns(columns, onColumnOrderChange, defaultSortFieldId, defaultSortAsc);
140140

141141
// 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-
// );
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+
);
152152

153153
// const tableColumnsBasedOnTable = React.useMemo(() => {
154154
// if (!isInnerTable) {
@@ -157,9 +157,9 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
157157
// return tableColumns.slice(0, index);
158158
// }, [index, isInnerTable, tableColumns]);
159159

160-
// const freezedColumns = React.useMemo(() => {
161-
// return tableColumns.slice(0, index);
162-
// }, [index, tableColumns]);
160+
const freezedColumns = React.useMemo(() => {
161+
return tableColumns.slice(0, index);
162+
}, [index, tableColumns]);
163163

164164
const [
165165
{
@@ -597,13 +597,14 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
597597
</Wrapper>
598598
</ResponsiveWrapper>
599599

600-
{/* {freezedColumns.length > 0 && (
600+
{!expandableRows && !isInnerTable && freezedColumns.length > 0 && (
601601
<div
602602
style={{
603603
position: 'absolute',
604-
top: '200px',
604+
top: 0,
605605
left: 0,
606606
maxWidth: '100%',
607+
border: '1px solid black',
607608
}}
608609
>
609610
<Table disabled={disabled} className="rdt_Table" role="table">
@@ -715,7 +716,7 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
715716
</Table>
716717
{footer && <div>{footer}</div>}
717718
</div>
718-
)} */}
719+
)}
719720
</div>
720721

721722
{enabledPagination && (

0 commit comments

Comments
 (0)