Can calling with updateValue() in customBodyRender() cause other columns to update?
See original GitHub issueExpected Behavior
Calling updateValue() in a column’s customBodyRender() either (or both):
- updates the entire row(?)
- reflects update in both
tableMeta.tableDataandtableMeta.rowData
(Or am I misusing updateValue()? ie: do I need to move all column value updates into React state so MUIDataTable’s data prop triggers updates?)
Current Behavior
In a row, if column A with customBodyRender() depends on the value of column B for its render value:
- A does not reflect B’s calls to
updateValue() tableMeta.tableDataandtableMeta.rowDatareflect different values (see image, below)
Steps to Reproduce (for bugs)
Sandbox: https://codesandbox.io/s/muidatatables-custom-toolbar-28cvu
- Configure a column to contain enable/disable buttons that trigger dialogs to confirm the action for the row
- Configure a row to render an
inputif the value of the enable/disable column is set to a specific value - Invoke the enable button and confirm via dialog
- The enable/disable column is updated, but the dependent column in the same row does not reflect the update
Your Environment
| Tech | Version |
|---|---|
| Material-UI | 4.11.0 |
| MUI-datatables | 3.1.5 |
| React | 16.13.1 |
| browser | Chromium Version 83.0.4103.106 (Official Build) snap (64-bit) |
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
How to use value in onClick event in customBodyRender in ...
When using customBodyRender the values from tableMeta shows correctly in a console.log() and if I choose to return for instance ...
Read more >SQL: UPDATE Statement
Let's look at an UPDATE example that shows how to update more than one column in a table. TIP: When you update multiple...
Read more >mui-datatables - npm
It comes with features like filtering, resizable columns, view/hide columns, draggable columns, search, export to CSV download, printing, ...
Read more >SQL Query to Update From One Table to Another Based on an ...
We can update the table using UPDATE statement in SQL. ... we can set the column name to be equal to the data...
Read more >Update a column value in a collection using ForAll
(Also note: the UpdateIf will return a table of modified records, should you need to capture the results for some reason.) The other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This appears to be a React issue. Check out this version of the sandbox where value is rendered rather than a TextBox:
https://codesandbox.io/s/muidatatables-custom-toolbar-q1nvp?file=/index.js
It sorts correctly and shows that value is matching up with where it should be. Additionally, if you change “defaultValue” to “value”, you’ll see that it sorts correctly too.
I believe React is diffing the component props and not detecting a difference (I’m guessing defaultValue has no effect for re-renders), so it’s not re-rendering them. You can force the TextField to re-render by setting it’s key property (I did that in the codesandbox above, you can see it if you comment out the first return).
I will need to think about this some. I’m pretty sure this line is the problem:
https://github.com/gregnb/mui-datatables/blob/master/src/MUIDataTable.js#L1059
Basically, tableData is pointing to the data that’s passed into the table. I’ll put this on my list to tackle next. In the meantime, one workaround solution would be to use customBodyRenderLite instead (it gives you the dataIndex. You’d update your data, and then the table would update).