superset icon indicating copy to clipboard operation
superset copied to clipboard

feat: add interactive column sorting to pivot table

Open SBIN2010 opened this issue 2 months ago • 17 comments

SUMMARY

This PR fix https://github.com/apache/superset/issues/23353

What was done

  • Added column sorting functionality to the pivot table
  • Implemented ascending (asc) and descending (desc) sorting
  • Added visual indicators for sorting state (icons)

Main changes

  • New sortData method - handles sorting logic and state updates
  • calculateGroups method - calculates aggregated values for sorting
  • sortAndCacheData method - sorts hierarchical data and caches results
  • Visual elements - added sorting icons in column headers

Implementation features

  • Sorting works with hierarchical data (including nested groups)
  • Support for various subtotal configurations (rowEnabled, rowPartialOnTop)
  • Caching of sorted data for performance

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Снимок экрана от 2025-11-09 12-04-33 Снимок экрана от 2025-11-09 12-04-58 Снимок экрана от 2025-11-09 12-08-38

TESTING INSTRUCTIONS

How to test

  1. Open pivot table with data
  2. Click sorting icon in column header
  3. Verify switching between asc/desc modes
  4. Ensure data sorts correctly

run superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx

ADDITIONAL INFORMATION

  • [ ] Has associated issue:
  • [ ] Required feature flags:
  • [ ] Changes UI
  • [ ] Includes DB Migration (follow approval process in SIP-59)
    • [ ] Migration is atomic, supports rollback & is backwards-compatible
    • [ ] Confirm DB migration upgrade and downgrade tested
    • [ ] Runtime estimates and downtime expectations provided
  • [ ] Introduces new feature or API
  • [ ] Removes existing feature or API

SBIN2010 avatar Nov 09 '25 09:11 SBIN2010

🎪 Showtime is building environment on GHA for 33ff764

github-actions[bot] avatar Nov 13 '25 14:11 github-actions[bot]

🎪 Showtime deployed environment on GHA for 33ff764

Environment: http://34.222.110.137:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically

github-actions[bot] avatar Nov 13 '25 15:11 github-actions[bot]

🎪 Showtime is building environment on GHA for a3e878d

github-actions[bot] avatar Nov 13 '25 16:11 github-actions[bot]

🎪 Showtime deployed environment on GHA for a3e878d

Environment: http://34.217.107.175:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically

github-actions[bot] avatar Nov 13 '25 16:11 github-actions[bot]

🎪 Showtime is building environment on GHA for 0e39890

github-actions[bot] avatar Nov 13 '25 17:11 github-actions[bot]

🎪 Showtime deployed environment on GHA for 0e39890

Environment: http://44.250.71.196:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically

github-actions[bot] avatar Nov 13 '25 17:11 github-actions[bot]

@alexandrusoare mind doing a quick review? I saw you are also working on a bunch of pivot table stuff too.

sadpandajoe avatar Nov 13 '25 18:11 sadpandajoe

Had a look, the code looks good, one thing though, I checked and the sorting only works if you click on the arrows, can we make it so that the sorting is applied when clicking on the column?

alexandrusoare avatar Nov 14 '25 15:11 alexandrusoare

🎪 Showtime is building environment on GHA for f3f6ae3

github-actions[bot] avatar Nov 14 '25 21:11 github-actions[bot]

Had a look, the code looks good, one thing though, I checked and the sorting only works if you click on the arrows, can we make it so that the sorting is applied when clicking on the column?

I thought about that too, but it won't work. The onClick method is already set in the Header, which is responsible for cross-filtering.

SBIN2010 avatar Nov 14 '25 21:11 SBIN2010

🎪 Showtime deployed environment on GHA for f3f6ae3

Environment: http://54.200.178.91:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically

github-actions[bot] avatar Nov 14 '25 21:11 github-actions[bot]

🎪 Showtime is building environment on GHA for d8da404

github-actions[bot] avatar Nov 15 '25 19:11 github-actions[bot]

🎪 Showtime deployed environment on GHA for d8da404

Environment: http://44.252.9.174:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically

github-actions[bot] avatar Nov 15 '25 19:11 github-actions[bot]

🎪 Showtime is building environment on GHA for 6a8e0bb

github-actions[bot] avatar Nov 17 '25 21:11 github-actions[bot]

🎪 Showtime deployed environment on GHA for 6a8e0bb

Environment: http://54.185.15.180:8080 (admin/admin) • Lifetime: 48h auto-cleanup • Updates: New commits create fresh environments automatically

github-actions[bot] avatar Nov 17 '25 22:11 github-actions[bot]

it will be nice if the total column also get the sorting functionality

jiangoxford avatar Dec 19 '25 10:12 jiangoxford

it will be nice if the total column also get the sorting functionality

also i found clicking a sorted column does not revert to the original unsorted order

jiangoxford avatar Dec 19 '25 10:12 jiangoxford