LearnNewsExamplesServices
Frontmatter
id9428
titleTreeStore: Implement hierarchical sorting for doSort override
stateClosed
labels
enhancementaiarchitecturegrid
assigneestobiu
createdAtMar 10, 2026, 2:15 PM
updatedAtMar 10, 2026, 2:58 PM
githubUrlhttps://github.com/neomjs/neo/issues/9428
authortobiu
commentsCount2
parentIssue9404
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMar 10, 2026, 2:58 PM

TreeStore: Implement hierarchical sorting for doSort override

Closed v12.1.0 enhancementaiarchitecturegrid
tobiu
tobiu commented on Mar 10, 2026, 2:15 PM

Goal

Implement a custom doSort() override in Neo.data.TreeStore that sorts sibling nodes while preserving the parent-child tree hierarchy.

Context

TreeStore currently inherits doSort() from Collection.Base, which simply sorts the flat _items array 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

  • Override doSort() in TreeStore.
  • The sorting algorithm must iterate through #childrenMap and sort each parent's array of children individually.
  • After structurally sorting the tree, it must perform a top-down recursive projection to completely recalculate the flattened _items array, ensuring parents always immediately precede their children in the flat view.
  • Ensure "Turbo Mode" (lazy instantiation) remains supported during this process.
  • Add a test case verifying the hierarchical sort order.
tobiu added the enhancement label on Mar 10, 2026, 2:15 PM
tobiu added the ai label on Mar 10, 2026, 2:15 PM
tobiu added the architecture label on Mar 10, 2026, 2:15 PM
tobiu added the grid label on Mar 10, 2026, 2:15 PM
tobiu added parent issue #9404 on Mar 10, 2026, 2:16 PM
tobiu
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 doSort override, please add a new test.describe block to this file.

Testing Requirements:

  1. Initialize a TreeStore with a known nested hierarchy.
  2. Apply a Sorter (e.g., descending alphabetically by name).
  3. Assert that the resulting flat _items array correctly orders siblings while strictly maintaining the parent -> child contiguous sequences. Parents must not be mixed globally with children.
  4. Ensure the test covers both Turbo Mode (autoInitRecords: false using raw objects) and standard mode (Records).
tobiu referenced in commit 5eaf2d6 - "feat: TreeStore hierarchical sorting override (#9428)" on Mar 10, 2026, 2:54 PM
tobiu assigned to @tobiu on Mar 10, 2026, 2:57 PM
tobiu
tobiu Mar 10, 2026, 2:58 PM

Input from Gemini 3.1 Pro:

✦ I have successfully implemented the hierarchical sorting logic for the TreeStore data layer:

  1. Turbo Mode support: TreeStore correctly soft-hydrates the entire allRecordsMap before sorting, ensuring the complex fields (like resolving 'name' from references if needed) are evaluated on raw nodes without instantiating them into Neo.data.Record objects unless strictly necessary.
  2. Hierarchical Sorting: Adapted the versatile sortArray logic from Neo.collection.Base to act locally on each array inside TreeStore.#childrenMap. This correctly sorts all siblings under a shared parent.
  3. Flat Tree Projection Re-calculation: After mapping the internal hierarchies, it utilizes collectVisibleDescendants starting from the root elements to generate a new correctly ordered contiguous _items array for the GridBody virtual scroller.
  4. 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 handles Turbo Mode seamlessly.

Closing the ticket!

tobiu closed this issue on Mar 10, 2026, 2:58 PM