question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Internal grid width / height estimation issue

See original GitHub issue

When Grid’s columnWidth or rowHeight prop is a function, the overall internal width or height is approximated rather than calculated precisely. I’m new to react-visualized, but I think I understand the purpose behind this design decision.

A negative side-effect being introduced by such an optimization is in that the scrollbars may start behaving unpredictably. The further a user scrolls, the better the approximation of the actual internal size of the grid, but the bigger the offset between the cursor and the scrollbar. This effect can be easily demonstrated in the official demo:

anim (the same happens with the vertical scrollbar when row height is set to be dynamic)

The reason why the size estimate is so wrong here is because the second and the third columns are rather wide while hundreds of the remaining ones are relatively narrow. The situation may be opposite, e.g. the grid may contain quite a compact title row and column followed by very large cells with charts and maps. In this case, the scroll bar will end up being behind the cursor, which may cause the cursor to run out of the browser window and thus unexpectedly reset the scroll position.

Although the existing approach to size estimation works well in most of the cases, introducing an option that would calculate all column widths and row heights in a grid feels potentially useful. It can be helpful for the grids that are large in size, but do not contain too many cells, i.e. in situations when calling all possible getColumnWidth / getRowHeight is very cheap, but the cost of a wrong guess is quite high. Perhaps, configuring estimate vs. precise calculation mode can be done independently for rows and columns.

What do you guys think of this potential extra option?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bvaughncommented, Jan 27, 2017

Yeah, good catch, @kachkaev. I’ll update my example to use componentDidUpdate instead.

1reaction
bvaughncommented, Jan 27, 2017

I quickly checked if ths this method exists for MultiGrid and discovered measureAllRows instead of measureAllCells there.

Whoops, that’s surely an oversight. Fixed with 8.11.2.

Because measureAllCells is a method rather than a prop, it’d be great to see a usage example or at least some hint on where to place it.

I have a lot of examples of using refs mixed around the docs. It’s hard (and probably not worth it) to try and show every possible example in the docs. Too much maintenance effort. 😄 But sure, something like this:

class ForcedMeasureGrid extends React.Component {
  constructor(props, context) {
    super(props, context);

    this._setRef = this._setRef.bind(this);
  }

  componentDidMount() {
    this._grid.measureAllCells();
  }

  componentDidUpdate(prevProps, prevState) {
    // Note that your invalidation conditions may be different.
    // The important part is: don't remeasure on every update.
    // That's wasted work.
    // Only remeasure if relevant props have changed.
    if (
      this.props.columnWidth !== prevProps.columnWidth ||
      this.props.rowHeight !== prevProps.rowHeight
    ) {
      // Clear cached sizes and then remeasure.
      this._grid.recomputeGridSize();
      this._grid.measureAllCells();
    }
  }

  render() {
    return (
      <Grid
        ref={this._setRef}
        {...this.props}
      />
    )
  }

  _setRef(ref) {
    this._grid = ref;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my Grid element's height not being calculated correctly?
The height of the grid container is fixed at 100px. The height of the grid item is set to 200%. A grid item...
Read more >
fit-content() - CSS: Cascading Style Sheets - MDN Web Docs
The function can be used as a track size in CSS Grid properties, where the maximum size is defined by max-content and the...
Read more >
Vue Data Grid: Grid Size - AG Grid
Under normal usage, your application should set the width and height of the grid using CSS styles. The grid will then fit the...
Read more >
Equal Height Elements: Flexbox vs. Grid
Once upon a time (approximately 2013), I wrote a jQuery plugin to calculate equal height columns. It ensured that the very specific scenario ......
Read more >
widthDetails: Width and Height of a grid grob - Rdrr.io
Description. These generic functions are used to determine the size of grid grobs. Usage. widthDetails(x) heightDetails(x) ascentDetails(x) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found