react-tabulator icon indicating copy to clipboard operation
react-tabulator copied to clipboard

Row and Cells are re-rendering for all state changes, not just data.

Open hprutsman opened this issue 6 years ago • 13 comments

Rows and Cell get re-rendered for all state changes

  • bug: Setting the state with unrelated changes causes re-rendering rows and cells

Short Description:

  • When I set a boolean value in the state that isn't passed to react-tabulator, the table rerenders the row and cell data anyways.

Environment Details

  • OS: Windows 10
  • Node.js version: 10.15.1
  • npm version: 6.4.1
  • browser: chrome 73.0.3683.75

Long Description In the example below, when editing data, I want to change the state to enable save button but when editing a large grid (30 columns, 10 rows) I noticed there was quite a bit of delay (1 sec?) when selecting the next column. If I remove the handleDataEdited prop, then it is very fast because the state doesn't get updated. I added the RowFormatter below to have it print a line in the console and sure enough, it prints for each row after setting the disabledSave in the state.

Code

handleDataEdited = (newData) => {
        this.setState({  disabledSave: false });
    }
render() {
        return (
           <div>
            <ReactTabulator
                columns={this.state.columns}
                data={this.state.data}
                dataEdited={this.handleDataEdited}
                options={{
                    clipboard: true,
                    clipboardCopyStyled: false,
                    clipboardPasteAction: "update",
                    height: 'auto',
                    layout: 'fitDataFill',
                    variableHeight: true,
                    reactiveData: true,
                    rowFormatter: RowFormatter //custom row formatter that just logs when called
                }}
            >
            </ReactTabulator>
            <Button color="primary" variant="contained" disabled={this.state.disabledSave} onClick={this.handleSave}>Save</Button>
           <div>
        )
    }

Workaround

...

Please help with a PR if you have a solution. Thanks!

hprutsman avatar May 15 '19 18:05 hprutsman

same issue. blew lots of time blaming it on hooks.

SuddenDevelopment avatar Jun 13 '19 00:06 SuddenDevelopment

Same issue here!

agustingrigoriu avatar Sep 05 '19 03:09 agustingrigoriu

Same there, banging my head on the wall for a couple of days now trying to find a workaround to set a call back with a state change after a row selection. Looks like any state change made out or next to tabulator component kind of breaks every behavior. For me changing the wrapping component's state with useState caused tabulator to miss randomly row selection and scrolling to top when selecting last rows. Commenting the set state with useState in the callback fixes the behavior.

SimoneIrato avatar Oct 04 '19 09:10 SimoneIrato

Thanks for reporting. I'm checking this, hopefully can fix it this weekend.

ngduc avatar Oct 05 '19 12:10 ngduc

It's strange. I can reproduce in this link: (React 16) https://codesandbox.io/s/react-tabulator-examples-ok3t0

but I couldn't reproduce in the Repo Example: (React 15) https://codesandbox.io/s/0mwpy612xw?module=/src/components/Home.js I refactored the Example a bit, moved "columns" into class, added setState & it works for me here (see "Selected Name"):

image

ngduc avatar Oct 05 '19 12:10 ngduc

The Repo Example uses React 15, But with React 16, in another project, I had an issue with another functional component keeps getting re-rendered. (had to keep it in the main render to avoid that)

ngduc avatar Oct 05 '19 12:10 ngduc

I've just fixed this bug (React 16 grid): componentDidUpdate called table.setData which kept re-rendering the grid. A check was put in to setData only when props data changed. Released 0.10.2. Let me know if you still have this issue.

ngduc avatar Oct 05 '19 13:10 ngduc

My issue is similar... when updating state (no states var related to the table), all selected rows get unselected (rowSelectionChanged callback is called...). I have no clue on how to fix this tho... Only way to bypass is to avoid call to setState (which is kinda react anti-patter...). Any idea ?

jmazier-j2d avatar Jun 29 '20 15:06 jmazier-j2d

My issue is similar... when updating state (no states var related to the table), all selected rows get unselected (rowSelectionChanged callback is called...). I have no clue on how to fix this tho... Only way to bypass is to avoid call to setState (which is kinda react anti-patter...). Any idea ?

Hello Jmazier-2d Even I am facing the same issue. Did you find any solution for it?

Abhijeet501 avatar Jan 28 '21 15:01 Abhijeet501

@Abhijeet501 @jmazier-j2d or somebody, can you post a Codesandbox example for troubleshooting? I'm reopening this issue to look into it further.. Thanks.

ngduc avatar Feb 27 '21 06:02 ngduc

Hi, were you able to solve the problem?

Marlom01 avatar Oct 06 '21 11:10 Marlom01

    <ReactTabulator
      id="table"
      style={{
        maxHeight: "100%",
        width: "98%",
      }}
      columns={[]}
      data={this.state.results}
      index="FileId"
      ref={(ref) => (this.gridSearchRef = ref)}
      options={{
        pagination: "local",
        paginationSize: 20,
        placeholder: "No Files Available",
      }}
              />

yes instead of adding columns directly into the react tabulator. I assigned it to null or empty like above example. after that used this way let gridcolumns = this.mapColumnsToGrid(); this.gridSearchRef.table.setColumns(gridcolumns);

Used separate method mapColumnsToGrid() to generate the required columns and then used setColumns to set it to Tabulator, this stopped columns and cells from re-rendering after every state change

Abhijeet501 avatar Oct 06 '21 20:10 Abhijeet501

@Abhijeet501 Wow, it works! Thanks for your solution <3, though I really have no idea how would this even work 🤔

hollen9 avatar May 07 '22 19:05 hollen9