Topic: Reordering search results removes hidden dashboard cards from storage
Mila Turner
pro
asked 1 week ago
The dashboard search renders only matching cards into our sortable grid. Reordering those results works, but saving the visible IDs replaces the complete workspace order and drops all cards outside the current search.
We want to change the order of the visible cards while keeping the hidden cards in their previous positions. The full ordered ID array is still available in our application state. How should the two lists be combined?
Igor Przybysz
staff
answered 1 week ago
Do not replace the complete saved order with the filtered DOM list. Keep the full array as the canonical order and replace only the positions occupied by the currently visible IDs. That preserves the hidden cards while applying the visible subset's new sequence.
Check that the submitted visible order contains each expected visible ID exactly once before merging. If cards can be added or removed during the interaction, reconcile that change with the complete array first rather than silently accepting an incomplete sequence.
https://mdbootstrap.com/docs/standard/plugins/drag-and-drop/
Mila Turner pro commented 1 week ago
The full state is [a, b, c, d], while the search displays a and c. After moving c before a, we save [c, a]. The hidden b and d should keep their original positions. This is the assignment that currently loses them.
const fullOrder = ['a', 'b', 'c', 'd'];
const visibleOrder = ['c', 'a'];
workspace.cardOrder = visibleOrder;
Igor Przybysz staff commented 1 week ago
Replace the visible slots in fullOrder rather than replacing the entire array. With your example, the merged order becomes [c, b, a, d], so b and d retain their positions.
Use the set of IDs visible when this reorder started, and validate the returned order against that set. In this fixed example, both visible IDs are present exactly once.
const visibleAtStart = new Set(['a', 'c']);
let nextVisible = 0;
workspace.cardOrder = fullOrder.map(id =>
visibleAtStart.has(id) ? visibleOrder[nextVisible++] : id
);
// ['c', 'b', 'a', 'd']
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: MDB Standard
- MDB Version: MDB5 9.3.0
- Device: Desktop
- Browser: Edge
- OS: Windows 11
- Provided sample code: No
- Provided link: No