Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable first column resize #43

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@

return (
<th
ref={column.dataColumn ? this._getColumnRef(columnIndex!) : null}

Check warning on line 276 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Forbidden non-null assertion
className={b('th', {sortable, align}, className)}
key={name}
title={headerTitle}
Expand Down Expand Up @@ -321,7 +321,7 @@
};
};
_getRenderedColumn = (index?: number) => {
if (index) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this condition was false for the first column, so resize for this column didn't work

if (index !== undefined) {
return this.renderedColumns[index];
}
return undefined;
Expand Down Expand Up @@ -821,7 +821,7 @@
/>
);
};
renderTable = (items: React.ReactNode[], ref?: any) => {

Check warning on line 824 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
const {
footerData,
columns: {dataColumns},
Expand Down Expand Up @@ -920,7 +920,7 @@

interface CellProps<T> {
column: Column<T>;
value?: any;

Check warning on line 923 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
row: T;
index: number;
footer?: boolean;
Expand All @@ -933,7 +933,7 @@
const {column, value, row, index, footer, headerData} = props;

return (
<React.Fragment>{column.render!({value, row, index, footer, headerData})}</React.Fragment>

Check warning on line 936 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Forbidden non-null assertion
);
}

Expand All @@ -959,7 +959,7 @@
defaultOrder: ASCENDING as OrderType,
defaultResizeable: false,
},
rowKey: (row: any, index: number) =>

Check warning on line 962 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
Object.prototype.hasOwnProperty.call(row, 'id') ? row.id : index,
initialSortOrder: {},
initialSortColumns: [],
Expand All @@ -972,7 +972,7 @@
stickyHead: Settings['stickyHead'] | false = false,
): HeadPositionInner {
if (stickyHead === MOVING && !positionStickySupported) {
console.warn(

Check warning on line 975 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
'Your browser does not support position: sticky, moving sticky headers will be disabled.',
);
return false;
Expand Down Expand Up @@ -1031,8 +1031,8 @@
}

state: DataTableViewState<T> = {
settings: {} as any, // see getDerivedStateFromProps

Check warning on line 1034 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
...externalToInternalSortOrder(this.props.initialSortOrder!, this.props.settings),

Check warning on line 1035 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Forbidden non-null assertion
};

table?: Table<T>;
Expand Down Expand Up @@ -1066,7 +1066,7 @@

const dataColumns = this.getComplexColumns(columns);
if (settings.dynamicRender && dataColumns.dataColumns.some((column) => column.group)) {
console.warn(

Check warning on line 1069 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
'Simultaneously used grouping cells and dynamic render. The table will render unpredictable.',
);
}
Expand Down Expand Up @@ -1149,7 +1149,7 @@
const _getValue =
typeof accessor === 'function'
? (row: T) => accessor(row)
: (row: any) => {

Check warning on line 1152 in src/lib/DataTable.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
return Object.prototype.hasOwnProperty.call(row, accessor)
? row[accessor]
: undefined;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/useTableResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ export type GetSavedColumnWidthByName = () => ColumnWidthByName;
export function updateColumnsWidth<T>(
columns: Column<T>[],
columnsWidthSetup: ColumnWidthByName,
defaultResizeable = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded parameter

): Column<T>[] {
return columns.map((column) => {
let sub: Column<T>[] | undefined;

if (column.sub) {
sub = updateColumnsWidth(column.sub, columnsWidthSetup, defaultResizeable);
sub = updateColumnsWidth(column.sub, columnsWidthSetup);
}

const newWidth = columnsWidthSetup[column.name] ?? column.width;
Expand Down
Loading