antd(3.x) table 数据量大时,批量全选卡顿

问题:antd(3.x) table 数据量大时,批量全选卡顿。

解决方案:
使用react-window的VariableSizeGrid组件结合antd table的Api(components.body.wrapper),将tbody以虚拟列表的方案渲染。
注意:需要结合rc-resize-observer监听宽度变化来处理宽度变化业务。

import { VariableSizeGrid as Grid } from "react-window";
import ResizeObserver from "rc-resize-observer";

1、tbody渲染虚拟列表方法

renderVirtualList = rawData => {
    const { children } = rawData;
    const { width } = this.state; // 通过rc-resize-observer监听到的宽度
    return (
      <Grid
        columnCount={1}
        columnWidth={() => {
          return width;
        }}
        rowCount={children.length}
        rowHeight={() => 95}
        width={width}
        height={475}
      >
        {({ rowIndex, style }) => {
          return (
            <div
              style={{
                ...style,
                width,
              }}
            >
              <table>
                <colgroup>
                  <col style={{ width: 60, minWidth: 60 }} />
                  <col style={{ width: 200, minWidth: 200 }} />
                  <col style={{ width: 110, minWidth: 110 }} />
                  <col />
                  <col />
                  <col style={{ width: 110, minWidth: 110 }} />
                  <col style={{ width: 110, minWidth: 110 }} />
                  <col />
                </colgroup>
                <tbody className="ant-table-tbody">{children[rowIndex]}</tbody>
              </table>
            </div>
          );
        }}
      </Grid>
    );
  };

2、宽度变化方法

  onResize = ({ width }) => {
    this.setState({
      width,
    });
  };

3、组件render

render(){
	const { onResize, renderVirtualList } = this;
	return (
		<ResizeObserver onResize={onResize}>
			<Table 
				// ... props,
				components={{
					body: {
						wrapper: renderVirtualList
					}
				}}
			/>
		</ResizeObserver>
	)
}

虚拟列表渲染时(为了偷懒)避免重写css,就直接以table包裹渲染children(可优化点)。

不喜勿喷 ~ ~ ~

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值