Skip to content

fix(TableStateful): Prevent in-place sorting in TableStateful to restore initial sort on NOS#7715

Merged
deleonio merged 2 commits intopublic-ui:developfrom
larrrssss:7634-reset-table-sorting
May 15, 2025
Merged

fix(TableStateful): Prevent in-place sorting in TableStateful to restore initial sort on NOS#7715
deleonio merged 2 commits intopublic-ui:developfrom
larrrssss:7634-reset-table-sorting

Conversation

@larrrssss
Copy link
Copy Markdown
Contributor

Problem

When using TableStateful, sorting a column modifies the original data array (_data) in place. As a result:

  • When users sort columns and then deselect sorting (i.e., return to "no sort" state / NOS), the table does not return to the original order.
  • The original sort is lost since it was overwritten by the last sorting operation.

Root Cause

In-place mutation of the _data array using .sort() mutates the original state reference, losing the pristine initial sort order.

Changes

  • Replaced reference assignment let sortedData = this.state._data with a spread copy const sortedData = [...this.state._data]
  • Applied sort on the copy instead of the original state

This PR fixes #7634

@publicuibot
Copy link
Copy Markdown
Contributor

publicuibot bot commented May 15, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@larrrssss
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@deleonio deleonio merged commit 99e28d1 into public-ui:develop May 15, 2025
8 of 9 checks passed
@publicuibot publicuibot bot locked and limited conversation to collaborators May 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Bug: TableStateful: column sorting does not return to initial sorting on NOS

2 participants