reactjs 如何修复Ant设计表版本3中的表头?

xuo3flqw  于 2023-03-17  发布在  React
关注(0)|答案(1)|浏览(192)

在Ant Design版本3中,我使用了table组件,并且我尝试给予位置:sticky to head〉th。
但它不起作用。
这个特性已经在Ant版本4中实现了,但是要移植到这个版本还需要很长时间。
我有什么办法可以补救吗?
我试着给予位置:粘在头上。
这对解决问题没有帮助
应使表头粘滞

dl5txlt9

dl5txlt91#

您需要在position: sticky中添加thead元素,如果您想坚持到页面顶部,还需要添加top: 0
例如组件

  1. import { Component } from 'react';
  2. import { Table } from 'antd';
  3. import styles from "./styles.module.scss";
  4. export default class TableSticky extends Component {
  5. render() {
  6. return (
  7. <Table
  8. className={styles.table}
  9. columns={columns}
  10. dataSource={data}
  11. pagination={false}
  12. />
  13. )
  14. }
  15. }

例如样式

  1. .table {
  2. & thead {
  3. position: sticky;
  4. top: 0;
  5. }
  6. }
展开查看全部

相关问题