Leonard-Li777 / antd-table-infinity

An infinite scroll component based on antd-table that supports virtual scrolling
Other
284 stars 47 forks source link

Cannot read property 'getElementsByTagName' of undefined #31

Open GeorgeCodeHub opened 4 years ago

GeorgeCodeHub commented 4 years ago

Hello there.

I'm unable to start a project with your library. Here is an example below:

https://stackblitz.com/edit/antd-infinity

I also tried making it in CodeSandbox and codePen and got the same issue.

Am I forgetting to add something?

kumawatanupriya commented 4 years ago

I am also getting the same issue. @GeorgeCodeHub did you find any solution?

GeorgeCodeHub commented 4 years ago

Sadly no. Something must be conflicting with either the antD or React lib...

marcellp commented 4 years ago

If you're still looking for a solution, the problem is that the code does not like an empty array for data. Having at least one row in the table by default is needed, otherwise the thing craps out.

RalfZhang commented 3 years ago

I found that the reason might be antd's version is too high. When I used antd v3.26.15, the component would run correctly.

I used antd v4.8.2. And I traced the error. It's cause of these codes

componentDidMount() {
    /* eslint-disable */
    this.refScroll = ReactDOM.findDOMNode(this).getElementsByClassName(
      'ant-table-body',
    )[0];
    this.refTable = this.refScroll.getElementsByTagName('tbody')[0];
    ...
}

I found ReactDOM.findDOMNode(this) is

<div class="ant-table-wrapper table">
  <div class="ant-spin-nested-loading">
    <div class="ant-table">
      <div class="ant-table-container">
        <div class="ant-table-content">
          <table>
            <colgroup>...</colgroup>
            <thead class="ant-table-thead">...</thead>
            <tbody class="ant-table-tbody">...</tbody>
          </table>
        </div> 
      </div>
    </div>
  </div>
</div>

It's obvious that this.refScroll would be undefinde.

If u change the code to

componentDidMount() {
    /* eslint-disable */
    this.refScroll = ReactDOM.findDOMNode(this).getElementsByClassName(
      'ant-table', // changed here
    )[0];
    this.refTable = this.refScroll.getElementsByTagName('tbody')[0];
    ...
}

The component would run correctly.

The last commit was pushed one year ago. So I think we should not use the package any more.