DataTable: Add externalSorting prop to disable client-side sorting#7488
Conversation
🦋 Changeset detectedLatest commit: f145a28 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the |
francinelucca
left a comment
There was a problem hiding this comment.
one change request, other than that LGTM!
Also let's not skip the integration tests 🙏🏽
| * table. Use this when sorting is handled server-side. The `onToggleSort` | ||
| * callback will still be fired when a sortable column header is clicked. | ||
| */ | ||
| externalSorting?: boolean |
There was a problem hiding this comment.
let's add this new prop to the DataTable props file as well -> https://github.com/primer/react/blob/main/packages/react/src/DataTable/DataTable.docs.json
|
👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the |
There was a problem hiding this comment.
Pull request overview
This PR adds a new externalSorting prop to the DataTable component to support server-side sorting scenarios. When enabled, the table maintains sort state UI (sort direction indicators and callbacks) without performing client-side data sorting, allowing consumers to handle sorting externally.
Changes:
- Added
externalSortingboolean prop to DataTable and useTable hook - Modified sortRows function to skip client-side sorting when externalSorting is true
- Added comprehensive test coverage for the new functionality
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 |
|---|---|
| packages/react/src/DataTable/DataTable.tsx | Added externalSorting prop to DataTableProps and passed it through to useTable hook |
| packages/react/src/DataTable/useTable.ts | Added externalSorting parameter to TableConfig and early return in sortRows function when enabled |
| packages/react/src/DataTable/tests/DataTable.test.tsx | Added comprehensive test verifying that client-side sorting is disabled while sort state and callbacks still function correctly |
| packages/react/src/DataTable/DataTable.docs.json | Added documentation for the new externalSorting prop |
| .changeset/calm-readers-send.md | Added changeset entry marking this as a minor release |
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/12364 |
This adds a new prop to the
DataTableto disable client-side sorting when theDataTableto improve the UX when the table is showing paginated data that is loaded from the server.Changelog
New
externalSortingprop toDataTableChanged
Removed
Rollout strategy
Testing & Reviewing
Merge checklist