Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.
This repository was archived by the owner on Jun 28, 2026. It is now read-only.

DataTable: stale edit state on new values set #8106

Description

@howkymike

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:

  • 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:

  1. The props.editingKey is set as the row's id.
  2. 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.

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

primereact: latest => 10.9.6 
react: 18.2.0 => 18.2.0

Steps to reproduce the behavior

  1. Open the editor for a cell with id=1 in the first dataset.
  2. Without closing the editor, switch to the second dataset.
  3. Open the editor for a cell with id=1 in the new dataset.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugIssue contains a defect related to a specific component.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions