Skip to content

fix(data-grid): persist cell updates when filtering is applied#1116

Merged
sadmann7 merged 3 commits intomainfrom
sadman/fix-data-grid-live-filter-persistence
Feb 24, 2026
Merged

fix(data-grid): persist cell updates when filtering is applied#1116
sadmann7 merged 3 commits intomainfrom
sadman/fix-data-grid-live-filter-persistence

Conversation

@sadmann7
Copy link
Copy Markdown
Owner

@sadmann7 sadmann7 commented Feb 24, 2026

Modified onDataUpdate in use-data-grid.ts to iterate over the complete dataset (currentData.length) instead of just filtered rows (tableRowCount). When filters were active, the function was building a partial data array containing only visible rows, causing onDataChange to miss updates for the complete dataset and preventing persistence to the database.

Fixes #1106

sadmann7 and others added 3 commits February 24, 2026 16:47
Fixes issue where cell edits in data-grid-live were not persisted to the database when filters were active. The problem was that onDataUpdate was building a newData array with only the filtered row count instead of the complete dataset.

When filters are applied:
- The table's row model contains only filtered rows
- But the data prop contains all rows (unfiltered)
- onDataUpdate needs to return all rows with updates applied

This fix ensures that when building the updated data array, we iterate over the complete currentData array (all rows) rather than just the visible filtered rows (tableRowCount). This allows onDataChange to properly detect and persist all updates to the database.

Fixes #1106

Co-authored-by: Cursor <[email protected]>
Added comprehensive tests to verify that cell updates work correctly when column filters are active:

1. Single filtered row update: Verifies that updating a cell in a filtered view correctly updates the full dataset (all 3 rows) rather than just the filtered rows

2. Multiple filtered rows update: Tests updating a cell when multiple rows are visible through filtering, ensuring the correct row in the full dataset is updated

These tests ensure the fix for #1106 is working correctly and prevent regression of the filtering + cell update bug.

All 96 tests passing.

Co-authored-by: Cursor <[email protected]>
Copilot AI review requested due to automatic review settings February 24, 2026 10:51
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tablecn Ready Ready Preview Feb 24, 2026 10:51am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a persistence bug in useDataGrid where cell edits made while column filters are active were not being applied back onto the full underlying dataset, causing DB updates to miss unfiltered rows.

Changes:

  • Update onDataUpdate to always rebuild newData using currentData.length (full dataset), not the filtered row count.
  • Add tests ensuring edits while filtered are applied to the correct underlying row and onDataChange receives the full dataset.
  • Update registry JSON snapshots to reflect onRowSelect using row.id (consistent with current source/types).

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

File Description
src/hooks/use-data-grid.ts Fixes filtered-edit persistence by applying updates onto the full data array.
src/hooks/test/use-data-grid.test.tsx Adds filter-aware edit tests and a simple filter function for the test columns.
public/r/data-grid-select-column.json Registry snapshot updated to use row.id for selection callbacks.
public/r/data-grid-filter-menu.json Registry snapshot updated to reflect onRowSelect signature using rowId.
Comments suppressed due to low confidence (3)

src/hooks/use-data-grid.ts:411

  • if (!existingRow) treats valid falsy row values (e.g. 0, false, "") as missing and replaces them with {}. Since TData is unconstrained, prefer a nullish check (existingRow == null) and avoid synthesizing an empty object unless the data model explicitly guarantees object rows.
        if (!existingRow) {
          newData[i] = {} as TData;
          continue;
        }

src/hooks/use-data-grid.ts:406

  • onDataUpdate rebuilds newData by looping over currentData.length on every edit. With large datasets (and especially during rapid edits/paste), this becomes O(n) per update even when only a few rows changed. Consider starting from a shallow copy of currentData and only cloning/applying changes for the indices present in rowUpdatesMap.
      const newData: TData[] = new Array(currentData.length);

      for (let i = 0; i < currentData.length; i++) {
        const updates = rowUpdatesMap.get(i);
        const existingRow = currentData[i];

src/hooks/test/use-data-grid.test.tsx:40

  • In simpleFilterFn, the parameter is named _columnId but is used. Rename it to columnId (or similar) to avoid the conventional meaning of a leading underscore (intentionally unused).
const simpleFilterFn = (
  row: { getValue: (id: string) => unknown },
  _columnId: string,
  filterValue: string,
) => {
  const value = String(row.getValue(_columnId) ?? "");
  return value.toLowerCase().includes(filterValue.toLowerCase());

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sadmann7 sadmann7 merged commit a7c4e8d into main Feb 24, 2026
11 checks passed
@sadmann7 sadmann7 deleted the sadman/fix-data-grid-live-filter-persistence branch February 24, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Data Grid Live not updating cell value correctly, specifically when filtering by "name contains XXX". Value is not persisted on refresh.

2 participants