gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.7k stars 931 forks source link

customBodyRender firing twice #598

Open mikeps34 opened 5 years ago

mikeps34 commented 5 years ago

Is there a reason why customBodyRender gets called twice? I noticed it on my current project, but then reproduced it on a sample project that I found.

I forked from someone elses code and added a console.log, you'll notice it is being called twice. https://codesandbox.io/s/p5m1m1kwwq

The first time it appears that updateValue is undefined, and the next time it has a value. My use case is probably different than most, as I am updating state depending on the row (infinite scrolling).

gabrielliwerant commented 5 years ago

I looked into it a little, and it seems it's needed for both the table rendering and after filters are applied (or not). It looks like it would be a major undertaking to disentangle it and keep everything working, so unless this generates a bug, I would say it's low priority for now.

ericpyle commented 5 years ago

@gabrielliwerant I also noticed that customBodyRender is getting called for rows that are not being displayed (e.g I can set rowsPerPage to 0, and still see customBodyRender fired twice for every row data not being displayed). That could make sense if it is used for searching/filtering, but as far as I can tell the filtering is done on the actual row data, not on the content being rendered (e.g. I can render some extra text that doesn't show up in matches or in filters). Seems like a potential performance boost to only call customBodyRender for rows that are on the page. Should I make a separate issue for this, or is row rendering critical to the table behavior in general (independent of what is displayed)?

ericpyle commented 5 years ago

@gabrielliwerant went ahead and asked the question as an issue: https://github.com/gregnb/mui-datatables/issues/645

gabrielliwerant commented 5 years ago

I looked into this again recently while working on a separate issue, and it looks like we're not double rendering, even though customBodyRender is being called twice. It's called once while determining filter data and it's called again when computing the rows to display, but it only actually renders the data after both are complete, as best as I can tell. So, although it may sometimes be inconvenient to have the function called twice, it actually shouldn't be that big of a detriment in terms of render performance.

However, it's definitely not ideal to be calling it twice, especially on very big data sets.

bkiac commented 4 years ago

I've also noticed that the first time customBodyRender is called, the tableMeta.rowData only contains the cell's value, and only on the second run is the tableMeta.rowData array available as intended.

Vn-ChemGio commented 4 years ago

I've also noticed that the first time customBodyRender is called, the tableMeta.rowData only contains the cell's value, and only on the second run is the tableMeta.rowData array available as intended.

yes, I had problem , too

DhruvSakhiya commented 4 years ago

I've also noticed that the first time customBodyRender is called, the tableMeta.rowData only contains the cell's value, and only on the second run is the tableMeta.rowData array available as intended.

I am also facing this problem.