Skip to content

Commit 330e731

Browse files
committed
performance tweak for frozen
1 parent 742e451 commit 330e731

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/Footer.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { cx, findTableByUuid } from "./util";
66
interface InnerFooterCellProps<T> {
77
width: number;
88
column: ColumnProps<T>;
9-
prevWidths: number[];
9+
prevWidth: number;
1010
}
1111

12-
const FooterCell = React.memo(function <T>({ prevWidths, ...rest }: InnerFooterCellProps<T>) {
12+
const FooterCell = React.memo(function <T>({ prevWidth, ...rest }: InnerFooterCellProps<T>) {
1313
// hooks
1414
const { rows } = useContext(TableContext);
1515

@@ -19,7 +19,7 @@ const FooterCell = React.memo(function <T>({ prevWidths, ...rest }: InnerFooterC
1919
width: width || undefined,
2020
minWidth: width || undefined,
2121
padding: !column.footer ? 0 : undefined,
22-
left: column.frozen ? prevWidths.reduce((pv, c) => pv + c, 0) : undefined
22+
left: column.frozen ? prevWidth : undefined
2323
};
2424

2525
const FooterCellComponent = column.footer;
@@ -113,7 +113,7 @@ const Footer = () => {
113113
key={c.key}
114114
column={c}
115115
width={pixelWidths[i]}
116-
prevWidths={pixelWidths.slice(0, i)}
116+
prevWidth={c.frozen ? pixelWidths.slice(0, i).reduce((pv, c) => pv + c, 0) : 0}
117117
/>
118118
))}
119119
</div>

src/Header.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { cx } from "./util";
77
interface HeaderCellProps<T> {
88
width: number;
99
column: ColumnProps<T>;
10-
prevWidths: number[];
10+
prevWidth: number;
1111
}
1212

1313
interface HeaderProps {
1414
children: React.ReactNode;
1515
style: React.CSSProperties;
1616
}
1717

18-
const HeaderCell = React.memo(function <T>({ column, width, prevWidths }: HeaderCellProps<T>) {
18+
const HeaderCell = React.memo(function <T>({ column, width, prevWidth }: HeaderCellProps<T>) {
1919
// hooks
2020
const { dispatch, sortColumn: col, sortDirection, onSort } = useContext(TableContext);
2121

@@ -26,7 +26,7 @@ const HeaderCell = React.memo(function <T>({ column, width, prevWidths }: Header
2626
cursor: column.sortable ? "pointer" : undefined,
2727
width: width || undefined,
2828
minWidth: width || undefined,
29-
left: column.frozen ? prevWidths.reduce((pv, c) => pv + c, 0) : undefined
29+
left: column.frozen ? prevWidth : undefined
3030
};
3131

3232
// function(s)
@@ -112,7 +112,7 @@ const Header = forwardRef(({ children, ...rest }: HeaderProps, ref: any) => {
112112
key={c.key}
113113
column={c}
114114
width={pixelWidths[i]}
115-
prevWidths={pixelWidths.slice(0, i)}
115+
prevWidth={c.frozen ? pixelWidths.slice(0, i).reduce((pv, c) => pv + c, 0) : 0}
116116
/>
117117
))}
118118
</div>

src/Row.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface TableCellProps<T> {
1010
row: T;
1111
index: number;
1212
width?: number;
13-
prevWidths: number[];
13+
prevWidth: number;
1414
column: ColumnProps<T>;
1515
isExpanded: boolean;
1616
clearSizeCache: CacheFunction;
@@ -70,15 +70,15 @@ const TableCell = React.memo(function <T>({
7070
width,
7171
column,
7272
isExpanded,
73-
prevWidths,
73+
prevWidth,
7474
clearSizeCache,
7575
onExpanderClick
7676
}: TableCellProps<T>) {
7777
// cell style
7878
const style: React.CSSProperties = {
7979
width: width || undefined,
8080
minWidth: width || undefined,
81-
left: column.frozen ? prevWidths.reduce((pv, c) => pv + c, 0) : undefined
81+
left: column.frozen ? prevWidth : undefined
8282
};
8383

8484
// expander
@@ -275,7 +275,7 @@ function Row<T>({
275275
isExpanded={isExpanded}
276276
clearSizeCache={clearSizeCache}
277277
onExpanderClick={onExpanderClick}
278-
prevWidths={pixelWidths.slice(0, i)}
278+
prevWidth={c.frozen ? pixelWidths.slice(0, i).reduce((pv, c) => pv + c, 0) : 0}
279279
/>
280280
))}
281281
</RowContainer>

0 commit comments

Comments
 (0)