Skip to content

Commit

Permalink
feat: scrollbar resizable logic
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed May 11, 2024
1 parent d55114b commit ee2a630
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 0 additions & 1 deletion docs/examples/column-resize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const Demo = () => {
return mergedWidth;
}}
/>
{/* <Table resizable style={{ width: 800 }} columns={columns} data={data} /> */}
</div>
);
};
Expand Down
31 changes: 28 additions & 3 deletions src/Header/HeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getColumnsKey } from '../utils/valueUtil';
import HeaderCell from './HeaderCell';

export interface RowProps<RecordType> {
cells: readonly CellType<RecordType>[];
cells: CellType<RecordType>[];
stickyOffsets: StickyOffsets;
flattenColumns: readonly ColumnType<RecordType>[];
rowComponent: CustomizeComponent;
Expand Down Expand Up @@ -60,6 +60,27 @@ const HeaderRow = <RecordType extends any>(props: RowProps<RecordType>) => {
additionalProps = cell.column.onHeaderCell(column);
}

// If the cell is the previous cell of the scrollbar and resizable, and fixed is not right, then the scrollbar is resizable
const isScrollBarCellAndResizable =
column.scrollbar &&
(cells[cells.length - 2].column as ColumnType<RecordType>).resizable &&
cells[cells.length - 2].column.fixed !== 'right';

// Whether this cell is in the previous cell of the scrollbar
const isScrollBarCellPreviousCell =
cells[cells.length - 1].column.scrollbar && cellIndex === cells.length - 2;

let resizable: boolean;
if (isScrollBarCellPreviousCell) {
if (column.fixed === 'right') {
resizable = (column as ColumnType<RecordType>).resizable;
} else {
resizable = false;
}
} else {
resizable = isScrollBarCellAndResizable || (column as ColumnType<RecordType>).resizable;
}

return (
<HeaderCell
{...cell}
Expand All @@ -72,8 +93,12 @@ const HeaderRow = <RecordType extends any>(props: RowProps<RecordType>) => {
{...fixedInfo}
additionalProps={additionalProps}
rowType="header"
columnKey={columnsKey[cellIndex]}
resizable={(column as ColumnType<RecordType>).resizable}
columnKey={
isScrollBarCellAndResizable
? columnsKey[columnsKey.length - 2]
: columnsKey[cellIndex]
}
resizable={resizable}
minWidth={(column as ColumnType<RecordType>).minWidth}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface CellType<RecordType> {
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
column?: ColumnsType<RecordType>[number];
column?: ColumnsType<RecordType>[number] & { scrollbar?: boolean };
colSpan?: number;
rowSpan?: number;

Expand Down

0 comments on commit ee2a630

Please sign in to comment.