antd的table横向滚动条固定在可视窗口底部
时间: 2023-12-04 10:02:12 浏览: 465
一个table表头固定,内容可滚动的实用例子
4星 · 用户满意度95%
可以通过设置 `scroll={{ x: true, y: 'calc(100vh - 300px)' }}` 来实现横向滚动条固定在可视窗口底部,其中 `x: true` 表示开启横向滚动条,`y: 'calc(100vh - 300px)'` 表示纵向滚动条与可视窗口底部相距 300px。具体实现代码如下:
```javascript
import React from 'react';
import { Table } from 'antd';
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
width: 100,
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
width: 100,
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
width: 150,
},
{
title: 'Action',
key: 'action',
width: 150,
render: () => (
<span>
<a>Edit</a>
<a>Delete</a>
</span>
),
},
];
const data = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
},
{
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
},
{
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sidney No. 1 Lake Park',
},
{
key: '4',
name: 'Jim Red',
age: 32,
address: 'London No. 2 Lake Park',
},
];
const App = () => (
<Table
columns={columns}
dataSource={data}
pagination={false}
scroll={{ x: true, y: 'calc(100vh - 300px)' }}
/>
);
export default App;
```
阅读全文