You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a single DataTable component to render multiple datasets, the editing state is not cleared upon switching datasets. This results in unexpected behavior when editing cells, as described below:
Scenario: If a cell with id=1 from the first dataset has a value of "foo" and is in edit mode, switching to a second dataset and opening the editor for a cell with the same id=1 (but with a value of "bar") results in a blank value ("") being displayed in the editor.
Worse Scenario: If both datasets have fields with the same names, the value displayed and persisted in the editor may incorrectly come from the previous dataset.
Root Cause Analysis
After debugging the PrimeReact internals, I observed the following:
The props.editingKey is set as the row's id.
The props.editingMeta object stores the editing state for rows in the table. However:
editingMeta is not cleared when switching datasets.
It behaves like a cache. Once data for a row's id is saved in editingMeta, it is not updated or refreshed when datasets are switched.
In the onEditingMetaChange function, if editingMeta[editingKey] is undefined, it sets the correct row data. However, if it is already defined, the cached (and potentially outdated) value persists from the previous dataset.
This mechanism leads to stale or incorrect values being displayed when switching datasets.
Open the editor for a cell with id=1 in the first dataset.
Without closing the editor, switch to the second dataset.
Open the editor for a cell with id=1 in the new dataset.
Notice that the editor shows the value from the previous dataset instead of the correct value for the current dataset.
Expected behavior
When opening a cell editor, the value displayed should always come from the active dataset, reflecting its current state. Any residual or outdated values from previously edited datasets should be cleared.
Solution Proposal
The root cause of this issue appears to stem from allowing multiple cell editors to be opened simultaneously. A possible solution would be to restrict editing to only one cell at a time. This would eliminate conflicts and ensure that the editing state remains consistent with the active dataset.
Describe the bug
When using a single DataTable component to render multiple datasets, the editing state is not cleared upon switching datasets. This results in unexpected behavior when editing cells, as described below:
Root Cause Analysis
After debugging the PrimeReact internals, I observed the following:
props.editingKeyis set as the row's id.props.editingMetaobject stores the editing state for rows in the table. However:editingMetais not cleared when switching datasets.editingMeta, it is not updated or refreshed when datasets are switched.onEditingMetaChangefunction, ifeditingMeta[editingKey]isundefined, it sets the correct row data. However, if it is already defined, the cached (and potentially outdated) value persists from the previous dataset.This mechanism leads to stale or incorrect values being displayed when switching datasets.
Problematic file: DataTable.js
Reproducer
You can reproduce the issue by using this demo:
https://stackblitz.com/edit/github-dbvsrcmp?file=src%2Fmain.tsx,src%2FGeneric.jsx,src%2Fservice%2FThirdService.jsx,src%2Fservice%2FSecondService.jsx,src%2FApp.tsx
Here’s an additional visualization of the behavior:
Screen.Recording.2025-06-27.at.11.06.37.mov
System Information
Steps to reproduce the behavior
Expected behavior
When opening a cell editor, the value displayed should always come from the active dataset, reflecting its current state. Any residual or outdated values from previously edited datasets should be cleared.
Solution Proposal
The root cause of this issue appears to stem from allowing multiple cell editors to be opened simultaneously. A possible solution would be to restrict editing to only one cell at a time. This would eliminate conflicts and ensure that the editing state remains consistent with the active dataset.