Skip to content

Commit 0bcf3bf

Browse files
committed
feat: add sticky
1 parent 337c5c9 commit 0bcf3bf

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

docs/demo/expandedSticky.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: expandedSticky
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/expandedSticky.tsx"></code>

docs/examples/expandedSticky.tsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, { useState } from 'react';
2+
import type { ColumnType } from 'rc-table';
3+
import Table from 'rc-table';
4+
import '../../assets/index.less';
5+
6+
const Demo = () => {
7+
const [expandedRowKeys, setExpandedRowKeys] = useState<readonly React.Key[]>([]);
8+
9+
const columns: ColumnType<Record<string, any>>[] = [
10+
{
11+
title: '手机号',
12+
dataIndex: 'a',
13+
width: 100,
14+
fixed: 'left',
15+
onCell: (_, index) => {
16+
const props: React.TdHTMLAttributes<HTMLTableCellElement> = {};
17+
if (index === 0) props.rowSpan = 1;
18+
if (index === 1) props.rowSpan = 2;
19+
if (index === 2) props.rowSpan = 0;
20+
return props;
21+
},
22+
},
23+
Table.EXPAND_COLUMN,
24+
{ title: 'Name', dataIndex: 'c' },
25+
{ title: 'Address', fixed: 'right', dataIndex: 'd', width: 200 },
26+
];
27+
28+
return (
29+
<div
30+
style={{
31+
height: 10000,
32+
}}
33+
>
34+
<h2>expanded & sticky</h2>
35+
<Table<Record<string, any>>
36+
rowKey="key"
37+
sticky
38+
scroll={{ x: 800 }}
39+
columns={columns}
40+
data={[
41+
{ key: 'a', a: '12313132132', c: '小二', d: '文零西路' },
42+
{ key: 'b', a: '13812340987', c: '张三', d: '文一西路' },
43+
{ key: 'c', a: '13812340987', c: '张夫', d: '文二西路' },
44+
]}
45+
expandable={{
46+
expandedRowOffset: 1,
47+
expandedRowKeys,
48+
onExpandedRowsChange: keys => setExpandedRowKeys(keys),
49+
expandedRowRender: record => <p style={{ margin: 0 }}>{record.key}</p>,
50+
}}
51+
className="table"
52+
/>
53+
</div>
54+
);
55+
};
56+
57+
export default Demo;

0 commit comments

Comments
 (0)