Sort groups by aggregate, key, or column (#1303)#1304
Merged
Conversation
NumberField never applied the `clear` state class nor reserved right padding, so the value sat under the clear icon when showClear was on. Mirror TextField's handling.
Group sorting could only order by key, ascending. This adds declarative group sorting and column-driven group sorting. - GroupAdapter grouping levels accept `sortField`/`sortDirection` or a `sorters` array, resolved against the group key fields, aggregate aliases and name. An explicit `comparer` still wins. - New `sortGroups` flag on Grid (maps to GroupAdapter `sortGroupsBySorters`): sorting a column whose field is a group key or aggregate reorders the groups; other columns leave group order intact. - Sort fields read straight off the GroupResult, no per-comparison cloning. - Docs and the grouping example updated; tests added. Closes #1303
- Move `ExtendedSorter` to `data/comparer` (the module that defines the sorting contract), re-exporting it from `ArrayAdapter` so `cx/ui` consumers are unaffected. It is now also available from `cx/data`. - Drop `comparer.ts`'s private, duplicate `Sorter` interface; the helpers now use the shared `ExtendedSorter`. - Simplify `sort()` to take `ExtendedSorter[]` instead of the redundant `Sorter[] | ExtendedSorter[]` union (a plain Sorter is already assignable). - Widen `Sorter.value` to `Prop<any>`: it is resolved via `getSelector` and is commonly a binding, not just an accessor function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1303.
Summary
GroupAdaptercould only order groups by key, ascending. This adds first-class group sorting by aggregate, key, or name — both declaratively and via interactive column sorting.Changes
GroupAdaptersortField+sortDirection, or asortersarray. Sort fields resolve against the group's key fields, aggregate aliases and$name, sosortField: "total"orders groups by an aggregate. Precedence: explicitcomparer→sortField/sorters→ implicit key order (unchanged default).sortGroupsBySortersflag: the active record sorters reorder groups too. A column only reorders groups at levels where its field is a group key or aggregate — sorting any other column leaves the configured group order untouched.GroupResult(no per-comparison cloning of group data).GridsortGroupsprop (wired tosortGroupsBySorters), so sorting a column header reorders groups when the field maps to a group key/aggregate. Ignored whenpreserveGroupOrderis set.GridGroupingConfigtyped withsortField/sortDirection/sorters.Docs & example
sortGroupsand sortable columns.grouping,grid, andgroup-adapterdocs.Tests
Black-box tests through
GroupAdapter.getRecordscovering aggregate/keysortField, multi-fieldsorters, default key order, explicit-comparer precedence, column-sort reordering, and the non-group-column fallback.yarn test→ 525 passing;yarn check-typesclean.Notes
-/+string-shorthand for direction was considered but dropped: it's not an existing CxJS idiom. Direction is expressed via the object form (sortField/sortDirection), consistent with the rest of the framework.