Skip to content

feat (DataTable): add getRowId support to get unique row key#690

Merged
paanSinghCoder merged 2 commits into
mainfrom
feat/unique-key-for-rows
Mar 12, 2026
Merged

feat (DataTable): add getRowId support to get unique row key#690
paanSinghCoder merged 2 commits into
mainfrom
feat/unique-key-for-rows

Conversation

@paanSinghCoder

@paanSinghCoder paanSinghCoder commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Description

Issue

  • DataTable used TanStack Table’s default row identity (array index).
    With sorting, grouping, or filtering, rows could get wrong React keys and cause rendering issues.

Usage

<DataTable
    data={data}
    columns={memoizedColumns}
    getRowId={row => row.id}
  >
    <DataTable.Toolbar />
    <DataTable.Search />
    <DataTable.Content />
</DataTable>

Fix

  • New optional prop: getRowId?: (row: TData, index: number) => string.
    It’s passed through as TanStack’s getRowId, so each row can have a stable key (e.g. getRowId={row => row.id}).
  • Docs and tests updated to use getRowId.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes, no bug fixes just code improvements)
  • Chore (changes to the build process or auxiliary tools and libraries such as documentation generation)
  • Style (changes that do not affect the meaning of the code (white-space, formatting, etc))
  • Test (adding missing tests or correcting existing tests)
  • Improvement (Improvements to existing code)
  • Other (please specify)

How Has This Been Tested?

[Describe the tests that you ran to verify your changes]

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (.mdx files)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Screenshots (if appropriate):

[Add screenshots here]

Related Issues

[Link any related issues here using #issue-number]

Summary by CodeRabbit

  • New Features

    • DataTable supports an optional custom row-id callback for stable row keys in sortable/filterable tables.
  • Documentation

    • Clarified column configuration guidance for performance (stable columns reference).
    • Added guidance to provide stable row IDs to avoid rendering issues when rows reorder.
  • Tests

    • Added tests verifying stable row keys and correct rendering when a row-id callback is provided.

@vercel

vercel Bot commented Mar 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Mar 12, 2026 5:16am

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Added a new optional getRowId prop to DataTable, wired into the table initialization so consumers can supply a stable per-row identifier; docs and tests were updated to document and verify this behavior.

Changes

Cohort / File(s) Summary
Component implementation & types
packages/raystack/components/data-table/data-table.tsx, packages/raystack/components/data-table/data-table.types.tsx
Added optional getRowId?: (row: TData, index: number) => string to DataTable props and passed it into the table setup as the React Table getRowId handler.
Documentation
apps/www/src/content/docs/components/datatable/props.ts, apps/www/src/content/docs/components/datatable/index.mdx
Documented the new getRowId prop and added guidance to pass a stable columns reference and provide getRowId for stable React keys in sortable/filterable tables.
Tests
packages/raystack/components/data-table/__tests__/data-table.test.tsx
Added tests asserting that providing getRowId produces stable row keys and renders rows correctly after reordering/sorting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble keys in twilight's hum,
A tidy id for each small rump.
When rows leap, sort, or glide away,
My strings keep them where they should stay.
Hop — stable render saved today. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding getRowId support to the DataTable component for stable row key generation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/unique-key-for-rows

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/raystack/components/data-table/__tests__/data-table.test.tsx`:
- Around line 579-593: The test's getRowKey callback returns a number
(TestData.id is typed number) but the DataTable.getRowKey prop expects a string;
fix by aligning types: change the TestData.id type to string or update the
getRowKey return type/signature to accept number (or cast the returned id to
string) so the TypeScript error is resolved, locating this in the test where
TestData is defined and where DataTable is rendered with getRowKey; additionally
add a focused assertion that verifies stable keys behavior (e.g., capture row
key values before and after a sort or re-render and assert they remain
consistent) to validate stable row identity.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 800a5a24-46f5-47c0-a3d9-329303c6c3be

📥 Commits

Reviewing files that changed from the base of the PR and between 14de0ba and 38e5cb2.

📒 Files selected for processing (5)
  • apps/www/src/content/docs/components/datatable/index.mdx
  • apps/www/src/content/docs/components/datatable/props.ts
  • packages/raystack/components/data-table/__tests__/data-table.test.tsx
  • packages/raystack/components/data-table/data-table.tsx
  • packages/raystack/components/data-table/data-table.types.tsx

Comment thread packages/raystack/components/data-table/__tests__/data-table.test.tsx Outdated
Comment thread apps/www/src/content/docs/components/datatable/props.ts Outdated
@paanSinghCoder paanSinghCoder changed the title feat (DataTable): add getRowKey support to get unique row key feat (DataTable): add getRowId support to get unique row key Mar 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/raystack/components/data-table/data-table.tsx`:
- Around line 122-128: The table currently passes the consumer-provided getRowId
directly into useReactTable while groupedData contains synthetic
GroupedData<TData> rows; wrap getRowId with a function that detects group header
rows (presence of subRows or group_key) and returns a stable synthetic id (e.g.,
derived from group_key and an index or prefix like `group-${group_key}`) for
those, and otherwise delegates to the original getRowId for leaf rows; locate
the useReactTable call and replace the getRowId argument with this wrapper so
GroupedData headers get unique, stable IDs while real TData rows still use the
consumer callback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a6510b72-afd0-46c4-a308-119272e7e244

📥 Commits

Reviewing files that changed from the base of the PR and between 38e5cb2 and bf3bb76.

📒 Files selected for processing (5)
  • apps/www/src/content/docs/components/datatable/index.mdx
  • apps/www/src/content/docs/components/datatable/props.ts
  • packages/raystack/components/data-table/__tests__/data-table.test.tsx
  • packages/raystack/components/data-table/data-table.tsx
  • packages/raystack/components/data-table/data-table.types.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/www/src/content/docs/components/datatable/props.ts
  • apps/www/src/content/docs/components/datatable/index.mdx

Comment thread packages/raystack/components/data-table/data-table.tsx
@paanSinghCoder paanSinghCoder merged commit f9b6a16 into main Mar 12, 2026
5 checks passed
@paanSinghCoder paanSinghCoder deleted the feat/unique-key-for-rows branch March 12, 2026 06:12
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.

[DataTable] Optimize IntersectionObserver, fix index keys, and improve sticky columns

2 participants