Skip to content

Conversation

@johanrd
Copy link
Contributor

@johanrd johanrd commented Jan 28, 2026

Summary

Makes ColumnReordering react to restored preferences, matching ColumnVisibility behavior.

Problem

ColumnReordering read preferences only once at construction:

columnOrder = new ColumnOrder({                                                                                                                                                                                                                                                                       
  existingOrder: this.read(),  // ← Called once, never again                                                                                                                                                                                                                                          
});                                                                                                                                                                                                                                                                                                   

When preferences were restored (e.g., from an API), ColumnVisibility would update but ColumnReordering would not.

Solution

Add a read callback that's called reactively:

columnOrder = new ColumnOrder({                                                                                                                                                                                                                                                                       
  read: () => this.read(),  // ← Called each time orderedMap is accessed                                                                                                                                                                                                                              
});  

The orderedMap getter now prefers the read() result (from preferences) over the local map, making it reactive to preference changes.

Builds upon #149, which can be closed if this is merged.

  • Use TrackedMap for plugins and columns containers so restore() triggers tracking
  • Add non-mutating getters (getPlugin, getColumn) to avoid "mutation during render" errors

Test plan

  • New test: "ColumnReordering reacts to restored preferences"
  • Verified test fails before fix, passes after
  • All 185 tests pass (with tracked builtins 4.0.0 override)

@NullVoxPopuli
Copy link
Contributor

can you rebase this one?

ColumnReordering now reacts to restored preferences, like ColumnVisibility.

Previously, column order was read from preferences only once at construction.
Now the `orderedMap` getter reads from preferences via a `read` callback,
making it reactive - when preferences are restored, column order updates.

Changes:
- Add `read` callback to ColumnOrder (replaces static `existingOrder`)
- `orderedMap` prefers preferences (via read) over local map for reactivity
- Local map still used as fallback when no preferences exist

Depends on: fix(preferences): make restore() reactive by using TrackedMap
@johanrd johanrd force-pushed the fix/column-reordering-reactive-preferences branch from 01537b5 to bc9d767 Compare January 28, 2026 06:11
@johanrd
Copy link
Contributor Author

johanrd commented Jan 28, 2026

@NullVoxPopuli done!

Side note: I was also thinking to explore if the preferences arg to headlessTable could accept a thunk (for reactive puprposes), where multiple tables on the same view should react to the same preferences adapter. Maybe niche – but maybe you have thoughts?

@NullVoxPopuli
Copy link
Contributor

seems like a fine overload to support

@NullVoxPopuli NullVoxPopuli added bug Something isn't working enhancement New feature or request labels Jan 28, 2026
@NullVoxPopuli NullVoxPopuli merged commit e24bfa0 into universal-ember:main Jan 28, 2026
12 of 16 checks passed
@github-actions github-actions bot mentioned this pull request Jan 28, 2026
@johanrd
Copy link
Contributor Author

johanrd commented Jan 28, 2026

thanks, see #156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants