2016-03-31 09:40:55 +08:00
---
2019-11-15 14:35:25 +08:00
order: 18
2016-08-15 07:54:01 +08:00
title:
en-US: Fixed Header
zh-CN: 固定表头
2016-03-31 09:40:55 +08:00
---
2016-01-24 15:39:34 +08:00
2016-08-15 08:07:03 +08:00
## zh-CN
2016-08-15 07:54:01 +08:00
2016-08-15 08:07:03 +08:00
方便一页内展示大量数据。
2016-08-15 07:54:01 +08:00
2019-11-01 10:41:07 +08:00
需要指定 column 的 `width` 属性,否则列头和内容可能不对齐。如果指定 `width` 不生效或出现白色垂直空隙,请尝试建议留一列不设宽度以适应弹性布局,或者检查是否有[超长连续字段破坏布局](https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241)。
2016-08-15 07:54:01 +08:00
2016-08-15 08:07:03 +08:00
## en-US
2016-08-15 07:54:01 +08:00
2016-08-15 08:07:03 +08:00
Display large amounts of data in scrollable view.
2016-01-24 15:39:34 +08:00
2019-11-01 10:41:07 +08:00
> Specify width of columns if header and cell do not align properly. If specified width is not working or have gutter between columns, please try to leave one column at least without width to fit fluid layout, or make sure no [long word to break table layout](https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241).
2016-03-06 22:44:58 +08:00
2022-05-19 09:46:26 +08:00
```tsx
import React from 'react';
2016-01-24 15:39:34 +08:00
import { Table } from 'antd';
2022-05-19 09:46:26 +08:00
import type { ColumnsType } from 'antd/lib/table';
2016-01-24 15:39:34 +08:00
2022-05-19 09:46:26 +08:00
interface DataType {
key: React.Key;
name: string;
age: number;
address: string;
}
const columns: ColumnsType< DataType > = [
2019-05-07 14:57:32 +08:00
{
title: 'Name',
dataIndex: 'name',
width: 150,
},
{
title: 'Age',
dataIndex: 'age',
width: 150,
},
{
title: 'Address',
dataIndex: 'address',
},
];
2016-01-24 15:39:34 +08:00
2022-05-19 09:46:26 +08:00
const data: DataType[] = [];
2016-01-24 15:39:34 +08:00
for (let i = 0; i < 100 ; i + + ) {
data.push({
key: i,
2016-10-02 08:47:42 +08:00
name: `Edward King ${i}` ,
2016-01-24 15:39:34 +08:00
age: 32,
2016-10-02 08:47:42 +08:00
address: `London, Park Lane no. ${i}` ,
2016-01-24 15:39:34 +08:00
});
}
2022-05-19 09:46:26 +08:00
const App: React.FC = () => (
2022-04-03 23:27:45 +08:00
< Table columns = {columns} dataSource = {data} pagination = {{ pageSize: 50 } } scroll = {{ y: 240 } } / >
2018-11-28 15:00:03 +08:00
);
2022-05-19 09:46:26 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```