Skip to content

Commit 7b26a22

Browse files
committed
feat: offset
1 parent 2ed330a commit 7b26a22

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

docs/examples/expandedRowSpan.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ const columns: ColumnsType = [
1111
width: 100,
1212
onCell: (_, index) => {
1313
const props: React.TdHTMLAttributes<HTMLTableCellElement> = {};
14-
if (index === 1) {
14+
if (index === 0) {
15+
props.rowSpan = 1;
16+
} else if (index === 1) {
1517
props.rowSpan = 4;
1618
} else if (index === 2) {
1719
props.rowSpan = 0;
1820
} else if (index === 3) {
1921
props.rowSpan = 0;
2022
} else if (index === 4) {
2123
props.rowSpan = 0;
24+
} else if (index === 5) {
25+
props.rowSpan = 1;
2226
}
2327

2428
return props;
@@ -46,7 +50,10 @@ const Demo = () => (
4650
rowKey="key"
4751
columns={columns}
4852
data={data}
49-
expandable={{ expandedRowRender: record => <p style={{ margin: 0 }}>{record.key}</p> }}
53+
expandable={{
54+
offset: 0,
55+
expandedRowRender: record => <p style={{ margin: 0 }}>{record.key}</p>,
56+
}}
5057
className="table"
5158
/>
5259
</div>

src/Body/BodyRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function getCellProps<RecordType>(
4747
onTriggerExpand,
4848
expandable,
4949
expandedKeys,
50+
offset,
5051
} = rowInfo;
5152

5253
const key = columnsKey[colIndex];
@@ -79,7 +80,7 @@ export function getCellProps<RecordType>(
7980

8081
// For expandable row with rowSpan,
8182
// We should increase the rowSpan if the row is expanded
82-
if (expandable && rowSpan > 1) {
83+
if (expandable && rowSpan > offset) {
8384
let currentRowSpan = rowSpan;
8485

8586
for (let i = index; i < index + rowSpan; i += 1) {

src/Table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ function Table<RecordType extends DefaultRecordType>(
842842
expandableType,
843843
expandRowByClick: expandableConfig.expandRowByClick,
844844
expandedRowRender: expandableConfig.expandedRowRender,
845+
offset: expandableConfig.offset,
845846
onTriggerExpand,
846847
expandIconColumnIndex: expandableConfig.expandIconColumnIndex,
847848
indentSize: expandableConfig.indentSize,

src/context/TableContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
ColumnsType,
44
ColumnType,
55
Direction,
6+
ExpandableConfig,
67
ExpandableType,
78
ExpandedRowRender,
89
GetComponent,
@@ -49,6 +50,7 @@ export interface TableContextProps<RecordType = any> {
4950
expandableType: ExpandableType;
5051
expandRowByClick: boolean;
5152
expandedRowRender: ExpandedRowRender<RecordType>;
53+
offset: ExpandableConfig<RecordType>['offset'];
5254
expandIcon: RenderExpandIcon<RecordType>;
5355
onTriggerExpand: TriggerEventHandler<RecordType>;
5456
expandIconColumnIndex: number;

src/hooks/useRowInfo.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function useRowInfo<RecordType>(
2727
| 'expandedKeys'
2828
| 'childrenColumnName'
2929
| 'onRow'
30+
| 'offset'
3031
> & {
3132
columnsKey: React.Key[];
3233
nestExpandable: boolean;
@@ -54,6 +55,7 @@ export default function useRowInfo<RecordType>(
5455
'childrenColumnName',
5556
'rowExpandable',
5657
'onRow',
58+
'offset',
5759
]);
5860

5961
const {
@@ -103,7 +105,6 @@ export default function useRowInfo<RecordType>(
103105

104106
// ========================= Column =========================
105107
const columnsKey = getColumnsKey(flattenColumns);
106-
107108
return {
108109
...context,
109110
columnsKey,

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export interface ExpandableConfig<RecordType> {
256256
rowExpandable?: (record: RecordType) => boolean;
257257
columnWidth?: number | string;
258258
fixed?: FixedType;
259+
offset?: number;
259260
}
260261

261262
// =================== Render ===================

0 commit comments

Comments
 (0)