• react中使用antd Table组件滚动加载数据的实现


    废话不多说,直接上代码。一目了然。

    import React, { Component } from "react";
    import { Table } from "antd";
    import PropTypes from "prop-types";
    
    class TableBar extends Component {
      constructor(props) {
        super(props);
        this.onScrollEvent = this.onScrollEvent.bind(this);
      }
    
      onScrollEvent() {
        if (this.scrollRef.scrollTop + this.scrollRef.clientHeight ===         
          this.scrollRef.scrollHeight) {
            console.info('到底了!');
            // 这里去做你的异步数据加载
        }
      }
    
      render() {
        const {
          dataSource,
          columns,
          loading,
          pagination,
          isBordered,
          onRowClickCb,
          scroll,
          titleCb,
          footerCb,
          rowSelection,
          rowKey
        } = this.props.config;
    
        return (
          <div
            onScrollCapture={() => this.onScrollEvent()}
            style={{ height: '200px', overflowY: 'scroll' }}
            ref={c => {
              this.scrollRef = c;
            }}
          >
          <Table
            dataSource={dataSource}
            columns={columns}
            rowKey={rowKey?rowKey:record => record.id}
            loading={loading}
            pagination={pagination}
            rowSelection={rowSelection}
            bordered={isBordered}
            scroll={scroll}
            onRowClick={onRowClickCb}
            title={titleCb}
            footer={ footerCb}
          />
          </div>
        );
      }
    }
    
    TableBar.propTypes = {
      config: PropTypes.shape({
        dataSource: PropTypes.array,
        columns: PropTypes.array.isRequired,
        loading: PropTypes.bool,
        isBordered: PropTypes.bool,
        scroll: PropTypes.object,
        onRowClickCb: PropTypes.func,
        titleCb: PropTypes.func,
        footerCb: PropTypes.func,
        rowSelection: PropTypes.object,
        pagination: PropTypes.oneOfType([PropTypes.object, PropTypes.bool])
      })
    };
    
    export default TableBar;
       

    借鉴地址:https://segmentfault.com/q/1010000016507297/a-1020000016507798

  • 相关阅读:
    Oracle登录报错-ORA-00119
    Oracle11g配置监听
    Python Turtle模块的简单应用
    Turtle模块基本方法和使用(画布)
    python+selenium自动化禅道登录测试
    Xlrd模块读取Excel文件数据
    Selenium原理
    Axure中的登陆界面和动画轮播
    SQL Server创建用户并分配权限
    EF实体框架创建方法
  • 原文地址:https://www.cnblogs.com/zyl-Tara/p/9767303.html
Copyright © 2020-2023  润新知