Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make virtualization work with selections #338

Open
bebraw opened this issue Mar 1, 2018 · 2 comments
Open

Make virtualization work with selections #338

bebraw opened this issue Mar 1, 2018 · 2 comments

Comments

@bebraw
Copy link
Member

bebraw commented Mar 1, 2018

Currently integrating virtualization and selections (selectabular) breaks table behavior. This likely needs some fix in the virtualization logic.

@priley86
Copy link

hey @bebraw - thanks again for this wonderful library. I believe it is slowly becoming dated though, and we have started taking in some of the source of this project and reimplementing it w/ latest React standards (new Context API, new lifecyeles, using React createRef appropriately etc.) in patternfly-react. We plan to continue fully supporting this library in our products for the foreseeable future, so you may start redirecting some folks if they are getting stuck...You can see our latest here:
https://github.com/patternfly/patternfly-react/tree/master/packages/patternfly-4/react-table

Demo:
http://patternfly-react.surge.sh/patternfly-4/components/table

The API is now much simpler and cleaner for our consumer...

Also, my reimplementation of reactabular-virtualized which currently supports sort and select is here (not yet merged in PF):
https://github.com/priley86/patternfly-react/tree/react-virtualized-extension/packages/patternfly-4/react-virtualized-extension

I have started to reimplement reactabular-virtualized and believe I have found a "livable" solution to this bug. Essentially what I am seeing is, after the Body recalculates rows/state from the incoming props (after a selection), the scrollTo position is reset after the rows re-render. This causes a loss of visual context and does not render the scroll position correctly. I did not dig deeper into reactabular-table to try to prevent this reset of scroll, but one can simply reset the scrollTo to its existing position after selection occurs (inside componentDidUpdate as a current workaround)...

  componentDidUpdate(prevProps) {
    this.checkMeasurements(prevProps);
  }

  checkMeasurements(prevProps) {
    // If there are no valid measurements or the rows have changed,
    // calculate some after waiting a while. Without this styling solutions
    // like Radium won't work as you might expect given they can take a while to set container height.
    if (this.initialMeasurement || (prevProps && prevProps.rows !== this.props.rows)) {
      // If the rows have changed, but the user has not scrolled, maintain the existing
      // scroll position
      if (this.ref.current) {
        this.ref.current.scrollTop = this.scrollTop;
      }
      this.timeoutId = setTimeout(() => {
        const rows = this.calculateRows(this.props);

        if (!rows) {
          // Refresh the rows to trigger measurement.
          this.forceUpdate();

          return;
        }

        this.setState(rows, () => {
          this.initialMeasurement = false;
        });
      }, 100);
    }
  }

Let me know what you think of this and happy to make a PR here if you like. If you have a better suggestion, I am all ears! Just figured I would share this solution for those searching...

@bebraw
Copy link
Member Author

bebraw commented Feb 3, 2019

@priley86 A PR would be most welcome even if it breaks the API for this particular package.

Another feature that would be good to add for virtualization is overscan (i.e. rendering rows before the visible ones).

Unfortunately I don't have a budget for working on the project at the moment but I don't mind reviewing, merging your PR, and pushing a new version out. If some commercial backing appears, I can find the time for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants