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

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

Open
hprutsman opened this issue May 15, 2019 · 13 comments
Open
Labels
bug Something isn't working todo

Comments

@hprutsman
Copy link

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!

@SuddenDevelopment
Copy link

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

@agustingrigoriu
Copy link

Same issue here!

@SimoneIrato
Copy link

SimoneIrato commented Oct 4, 2019

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.

@ngduc
Copy link
Owner

ngduc commented Oct 5, 2019

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

@ngduc
Copy link
Owner

ngduc commented Oct 5, 2019

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
Copy link
Owner

ngduc commented Oct 5, 2019

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
Copy link
Owner

ngduc commented Oct 5, 2019

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 ngduc added the bug Something isn't working label Oct 5, 2019
@jmazier-j2d
Copy link

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 ?

@Abhijeet501
Copy link

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?

@ngduc
Copy link
Owner

ngduc commented Feb 27, 2021

@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 ngduc reopened this Feb 27, 2021
@ngduc ngduc added the todo label Feb 27, 2021
@Marlom01
Copy link

Marlom01 commented Oct 6, 2021

Hi, were you able to solve the problem?

@Abhijeet501
Copy link

Abhijeet501 commented Oct 6, 2021

    <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

@hollen9
Copy link

hollen9 commented May 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working todo
Projects
None yet
Development

No branches or pull requests

9 participants