Sort a lookup column from its header
Sort a lookup column from its header. Builds on the lookup columns from #30439, which is merged, and on the server column from #30657. This PR targets #30657's branch, so the diff shows only the front part. Retarget to main once #30657 merges.
On a lookup column such as Company › Name on People, Sort in the column header orders the rows by the looked-up field: orderBy: [{ company: { name: AscNullsLast } }]. Clicking it again flips the direction. The sort chip reads "Company → Name", and saving the view stores the sort with its target.
Release order: this PR selects viewSort.relationTargetFieldMetadataId and writes it. Per UPGRADE_COMMANDS.md, front-end use of a new column waits until the release containing #30657 is deployed, so this should merge in a later release than #30657.
Changes
Front-only (14 files, +218 −47):
- Sorts carry a target:
RecordSortandViewSortgetrelationTargetFieldMetadataId. The view sort fragment selects it, and saving a view (useSaveRecordSortsToViewSorts,useCreateViewFromCurrentView) writes it.areViewSortsEqualcompares it, so changing only the target is saved as an update. - Query:
turnSortsIntoOrderByorders a sort with a target by that field of the related record, through the sharedgetOrderByForRelationField. A relation sort without a target still orders by the related record's label field. - Header:
useHandleToggleColumnSorttakes the lookup's target. It flips the direction only when the existing sort has the same target; otherwise it starts a new ascending sort. Sort shows when the looked-up field is sortable: the same selector as Filter, asked about the looked-up field. - Chip:
EditableSortChiplabels a sort with a target "Relation → Field" (the label util from #30653, renamed togetRelationTargetFieldLabelsince both chips use it). Sub-field choices, e.g. which part of an address, come from the looked-up field.
A view sorts a field at most once (unique index on view and field), so a lookup column's sort and its relation column's sort replace each other. A header click already replaces all sorts.
Stack
| PR | What it does | Builds on |
|---|---|---|
| #30439 | Front: lookup columns and their header filter (with #30653) | merged |
| #30657 | Server: viewSort.relationTargetFieldMetadataId | main |
| 👉 this PR | Front: sort a lookup column from its header | #30657 |
Size: code +74 −19, tests +120 −4, regenerated graphql.ts +24 −24 (S).
Testing
- Unit:
turnSortsIntoOrderByorders a lookup sort by the looked-up field ({ company: { employees: DescNullsLast } }).useHandleToggleColumnSortreplaces a relation sort with a lookup sort, then flips it. The sort, view, record-index and table header suites pass (46 suites, 219 tests). - Browser check on the dev seed, with the server built from this branch and its instance command applied:
- The Company › Name header menu shows Sort.
- Sort sends
orderBy: [{ company: { name: AscNullsLast } }], and rows start with 2020, 3Pillar Global, 6sense. Clicking again sendsDescNullsLast(webOS, uTest, project44). - The chip reads "Company → Name".
- Update view stores the sort with its target (
viewSort.relationTargetFieldMetadataIdset), and after a reload the table is still sorted by Company › Name descending.
- Front typecheck, oxlint and oxfmt.
generated-metadata/graphql.tswas regenerated against the schema of #30657.
Screenshots
Sort in a lookup column's header menu:

Sorted by Company › Name, ascending:

After saving the view and reloading (descending):

Generated by Claude Code
Generated by Claude Code