Frontmatter
| id | 9428 |
| title | TreeStore: Implement hierarchical sorting for doSort override |
| state | Closed |
| labels | enhancementaiarchitecturegrid |
| assignees | tobiu |
| createdAt | Mar 10, 2026, 2:15 PM |
| updatedAt | Mar 10, 2026, 2:58 PM |
| githubUrl | https://github.com/neomjs/neo/issues/9428 |
| author | tobiu |
| commentsCount | 2 |
| parentIssue | 9404 |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Mar 10, 2026, 2:58 PM |
TreeStore: Implement hierarchical sorting for doSort override
tobiu added parent issue #9404 on Mar 10, 2026, 2:16 PM

tobiu
Mar 10, 2026, 2:36 PM
Input from Gemini 3.1 Pro:
✦ Implementation Guidance for Future Sessions:
We have established a robust Playwright unit testing environment for the data layer in
test/playwright/unit/data/TreeStore.spec.mjs.When implementing the hierarchical
doSortoverride, please add a newtest.describeblock to this file.Testing Requirements:
- Initialize a
TreeStorewith a known nested hierarchy.- Apply a Sorter (e.g., descending alphabetically by name).
- Assert that the resulting flat
_itemsarray correctly orders siblings while strictly maintaining the parent -> child contiguous sequences. Parents must not be mixed globally with children.- Ensure the test covers both Turbo Mode (
autoInitRecords: falseusing raw objects) and standard mode (Records).
tobiu assigned to @tobiu on Mar 10, 2026, 2:57 PM

tobiu
Mar 10, 2026, 2:58 PM
Input from Gemini 3.1 Pro:
✦ I have successfully implemented the hierarchical sorting logic for the
TreeStoredata layer:
- Turbo Mode support:
TreeStorecorrectly soft-hydrates the entireallRecordsMapbefore sorting, ensuring the complex fields (like resolving 'name' from references if needed) are evaluated on raw nodes without instantiating them intoNeo.data.Recordobjects unless strictly necessary.- Hierarchical Sorting: Adapted the versatile
sortArraylogic fromNeo.collection.Baseto act locally on each array insideTreeStore.#childrenMap. This correctly sorts all siblings under a shared parent.- Flat Tree Projection Re-calculation: After mapping the internal hierarchies, it utilizes
collectVisibleDescendantsstarting from therootelements to generate a new correctly ordered contiguous_itemsarray for theGridBodyvirtual scroller.- Tested in Playwright: 2 test cases were added to
test/playwright/unit/data/TreeStore.spec.mjs, covering deep hierarchical sorting for both ASC and DESC orders, and enforcing that the hierarchy handlesTurbo Modeseamlessly.Closing the ticket!
tobiu closed this issue on Mar 10, 2026, 2:58 PM
Goal
Implement a custom
doSort()override inNeo.data.TreeStorethat sorts sibling nodes while preserving the parent-child tree hierarchy.Context
TreeStorecurrently inheritsdoSort()fromCollection.Base, which simply sorts the flat_itemsarray globally. If you apply a sorter (e.g., alphabetical by name), it will mix parents and children, completely destroying the visual tree structure.Acceptance Criteria
doSort()inTreeStore.#childrenMapand sort each parent's array of children individually._itemsarray, ensuring parents always immediately precede their children in the flat view.