react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Dynamic row height

Open thomasdejagere opened this issue 9 years ago • 21 comments

WHICH VERSION OF REACT ARE YOU USING?

Officially Supported:
[X] v0.14.x
Community Supported:
[ ] v15.0.x

WHICH BROWSER ARE YOU USING?

Officially Supported:
[ ] IE 9 / IE 10 / IE 11
[ ] Edge
[X] Chrome
Should work:
[ ] Firefox
[ ] Safari

I'm submitting a ... (check one with "x")

[ ] bug report
[X] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/adazzle/react-data-grid/blob/master/CONTRIBUTING.md

Current behavior The row height is a fixed value. The height value can be specified through the "rowHeight" property of the ReactDataGrid component. There is no (clear) way to have rows with a variable row height.

Expected/desired behavior The height of the cell (and row) must be automatically changed to the height of the rendered html in the cell.

Reproduction of the problem chrome_2017-02-21_14-34-18

What is the motivation / use case for changing the behavior? I want to render html from string in a cell.

thomasdejagere avatar Feb 21 '17 13:02 thomasdejagere

For latecomers, i can confirm that it can be easily done by returning <ReactDataGrid.Row height={your_desired_height}/> in the rowRenderer function & implement your own formatter if you have troubles rendering the line break. (split and render each line as a div)

raymondtam avatar Jul 14 '17 09:07 raymondtam

@raymondtam returning <ReactDataGrid.Row height={your_desired_height}/> in the rowRenderer was able to produce rows of different heights but the moment I start to scroll the grid beyond the initial viewport, the grid goes into an infinite loop of re-rendering the rows. Any guidance on overcoming this?

Using version 2.0.69

vijayrajaram avatar Oct 31 '17 15:10 vijayrajaram

@vijayrajaram Did you ever get an answer to this or find a work around? I'm running into the same issue.

Edit (January 2018): We weren't able to find an appropriate work around for this and have decided to use react-virtualized instead

ChelseaCallan avatar Nov 21 '17 19:11 ChelseaCallan

I have a need for this as well. Is there a way to overload the scroll function or access the virtualizer to implement something for variable row heights? Maybe in the RowRenderer?

danlittlejohn avatar Dec 11 '17 23:12 danlittlejohn

I am also stuck in the same issue !!

sunil-srma avatar Jan 15 '18 09:01 sunil-srma

I have something that mostly works, but is not great. My implementation does not have many rows and columns so I decided to force overscan

            <TableDataGrid
                // use overScan to prevent table virtual rows
                // this renders all rows without any virtual / rendering on demand
                // does not work with columns
                overScan={{
                    colsStart: columnCount,
                    colsEnd: columnCount,
                    rowsStart: overScanRows,
                    rowsEnd: overScanRows,
                }}

This worked horizontally, but still had a lot of re-rendering horizontally so I fixed it to always render from the first column by extending the class.

class TableDataGrid extends ReactDataGrid {
    render() {
        // force viewport columns to always start from zero
        // to prevent row re-rendering when scrolling horizontally
        if (this.base && this.base.viewport) {
            this.base.viewport.getVisibleColStart = () => 0;
        }
        return super.render();
    }
}

On safari it is still has issues with header and body not scrolling together smoothly, but it is at least usable. We are likely going to replace react-data-grid unless we can fix the remaining issues.

danlittlejohn avatar Jan 25 '18 18:01 danlittlejohn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please reopen this if you feel it has been incorrectly closed and we will do our best to look into it. Thank you for your contributions.

stale[bot] avatar Jul 12 '18 13:07 stale[bot]

Anyone is working on this feature ?

sunil-srma avatar Aug 24 '18 07:08 sunil-srma

Yeah, this shouldn't have been close. Still needs to be looked at.

sontek avatar Nov 15 '18 14:11 sontek

Is there any solution for re-rendering when scrolling?

AliAlperSakar avatar Mar 16 '19 12:03 AliAlperSakar

Just fyi, seems like this might be fixed in the latest version... I haven't tried in my code yet because we need to upgrade, but I just tried on the example here: https://adazzle.github.io/react-data-grid/docs/examples/render-base-row changing the RowRender to have a variable row height:

const RowRenderer = ({ renderBaseRow, ...props }) => {
  const color = props.idx % 2 ? "green" : "blue";
  return <div style={{ color }}>{renderBaseRow({...props, height: (((props.idx % 2) + 1) * 40)})}</div>;
};

and it seemed to work

JSoet avatar Apr 11 '19 16:04 JSoet

This project is kind of a joke. Every real issue gets closed and nobody looks at it. I get being busy, but don't close real issues without updating us...

zackify avatar Apr 12 '19 18:04 zackify

Any updates? I need the rows height to be dynamic

sammysamx20 avatar May 29 '19 05:05 sammysamx20

Just fyi, seems like this might be fixed in the latest version... I haven't tried in my code yet because we need to upgrade, but I just tried on the example here: https://adazzle.github.io/react-data-grid/docs/examples/render-base-row changing the RowRender to have a variable row height:

const RowRenderer = ({ renderBaseRow, ...props }) => {
  const color = props.idx % 2 ? "green" : "blue";
  return <div style={{ color }}>{renderBaseRow({...props, height: (((props.idx % 2) + 1) * 40)})}</div>;
};

and it seemed to work

I just gave his example a try in Chrome and when you scroll down the top rows start flickering. Also when I scrolled down slowly it kept trying to take me back to the top of the grid (scroll down slowly and you keep going back to the first few rows).

Joel-Lowther avatar Jan 08 '20 17:01 Joel-Lowther

Where is the fix for the dynamic height of the row ?

umanga907 avatar Apr 18 '23 06:04 umanga907

how i can set dynamic height of table based on rows ...?

omair115 avatar Feb 20 '24 06:02 omair115

why close? still cant auto height

faisolavolut avatar Jun 06 '24 06:06 faisolavolut

what the solution for dynamic height of ReactData grid ...?

omair115 avatar Jun 19 '24 14:06 omair115

Still waiting for...

Fi1osof avatar Aug 26 '24 01:08 Fi1osof

please suggest another library

anisimov-evgeniy avatar Nov 11 '24 16:11 anisimov-evgeniy