Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit c520ab0

Browse files
committed
remove total width
1 parent 72dd1a7 commit c520ab0

File tree

6 files changed

+7
-21
lines changed

6 files changed

+7
-21
lines changed

src/cdm/StyleModel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export type ColumnWidthState = {
2-
widthRecord: Record<string, number>,
3-
totalWidth: number
2+
widthRecord: Record<string, number>
43
}
54

65
export type HeaderContextType = {

src/components/Header.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ export default function Header(headerProps: DatabaseHeaderProps) {
9292
columnWidthState.widthRecord[columnName] =
9393
(columnLabel.length + WidthVariables.ICON_SPACING) *
9494
WidthVariables.MAGIC_SPACING;
95-
// Add new width to the total width
96-
columnWidthState.totalWidth =
97-
columnWidthState.totalWidth +
98-
(columnLabel.length + WidthVariables.ICON_SPACING) *
99-
WidthVariables.MAGIC_SPACING;
10095
setColumnWidthState(columnWidthState);
10196
return { name: columnName, position: columnNumber, label: columnLabel };
10297
}

src/components/HeaderMenu.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
144144
key: keyState,
145145
});
146146
setExpanded(false);
147-
// Adjust the width of the columns
148-
columnWidthState.totalWidth =
149-
columnWidthState.totalWidth - columnWidthState.widthRecord[id];
150147
delete columnWidthState.widthRecord[id];
151148
setColumnWidthState(columnWidthState);
152149
},

src/components/Table.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ export function Table(initialState: TableDataType) {
234234
<HeaderNavBar
235235
csvButtonProps={csvButtonProps}
236236
globalFilterRows={globalFilterRows}
237-
headerGroupProps={headerGroups[0].getHeaderGroupProps()}
237+
headerGroupProps={headerGroups[0].getHeaderGroupProps({
238+
style: { width: totalColumnsWidth },
239+
})}
238240
/>
239241
{/** Headers */}
240242
{headerGroups.map((headerGroup, i) => (
@@ -282,7 +284,7 @@ export function Table(initialState: TableDataType) {
282284
{...headerGroup.getHeaderGroupProps({
283285
style: {
284286
...headerGroup.getHeaderGroupProps().style,
285-
maxWidth: `${columnsWidthState.totalWidth}px`,
287+
maxWidth: `${totalColumnsWidth}px`,
286288
},
287289
})}
288290
ref={droppableProvided.innerRef}
@@ -350,7 +352,7 @@ export function Table(initialState: TableDataType) {
350352
...cell.getCellProps({
351353
style: {
352354
...cell.getCellProps().style,
353-
maxWidth: `${columnsWidthState.totalWidth}px`,
355+
maxWidth: `${totalColumnsWidth}px`,
354356
},
355357
}),
356358
className: `${c("td")}`,

src/components/styles/ColumnWidthStyle.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ const lengthOfNormalizeCellValue = (row: any, accessor: string): number => {
2525

2626
const getColumnsWidthStyle = (rows: Array<Row<object>>, columns: TableColumn[]): ColumnWidthState => {
2727
const columnWidthStyle: ColumnWidthState = {
28-
widthRecord: {},
29-
totalWidth: 0
28+
widthRecord: {}
3029
}
3130
columns.forEach((column: TableColumn) => {
3231
columnWidthStyle.widthRecord[column.id] = getColumnWidthStyle(rows, column.key, column.label);
33-
columnWidthStyle.totalWidth += columnWidthStyle.widthRecord[column.id];
3432
})
3533
return columnWidthStyle
3634
}

src/helpers/StylesHelper.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,5 @@ export function recalculateColumnWidth(columnWidthState: ColumnWidthState, colum
3232
columnWidthState.widthRecord[columnName] =
3333
(columnLabel.length + WidthVariables.ICON_SPACING) *
3434
WidthVariables.MAGIC_SPACING;
35-
// Add new width to the total width
36-
columnWidthState.totalWidth =
37-
columnWidthState.totalWidth +
38-
(columnLabel.length + WidthVariables.ICON_SPACING) *
39-
WidthVariables.MAGIC_SPACING;
4035
return columnWidthState;
4136
}

0 commit comments

Comments
 (0)