fix(data-grid): row selection selects correct row when filtering is applied#1113
Merged
fix(data-grid): row selection selects correct row when filtering is applied#1113
Conversation
Use row.id instead of row.index for onRowSelect to fix incorrect row selection when data is filtered. Row selection state is keyed by row.id, so using the id directly ensures the correct row is selected regardless of filtering/sorting. Fixes #1107 Co-authored-by: Cursor <cursoragent@cursor.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where selecting rows in a filtered data grid would select incorrect rows. The issue occurred because row selection was using row indices (which change with filtering/sorting) instead of stable row IDs.
Changes:
- Changed
onRowSelectsignature from acceptingrowIndex: numbertorowId: string - Updated row selection state tracking to use
lastClickedRowIdinstead oflastClickedRowIndex - Added comprehensive test coverage for row selection with filtering applied
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/data-grid.ts | Updated onRowSelect type signature to accept rowId: string instead of rowIndex: number |
| src/hooks/use-data-grid.ts | Modified state tracking to use row IDs, updated onRowSelect implementation to find rows by ID, and properly handle shift-selection with ID lookups |
| src/hooks/test/use-data-grid.test.tsx | Added getRowId to existing tests and created new test validating correct row selection with filtering |
| src/components/data-grid/data-grid-select-column.tsx | Updated component to pass row.id instead of row.index to onRowSelect |
| src/app/data-grid-render/components/data-grid-render-demo.tsx | Updated demo component to pass row.id instead of row.index to onRowSelect |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use row.id instead of row.index for onRowSelect to fix incorrect row selection when data is filtered. Row selection state is keyed by row.id, so using the id directly ensures the correct row is selected regardless of filtering/sorting.
Fixes #1107