Skip to content

fix(grid): consistent sorting for columns with mixed primitive types - #173

Merged
Blankll merged 2 commits into
masterfrom
fix/grid-sort-mixed-type-columns
Oct 8, 2026
Merged

Blankll merged 2 commits into
masterfrom
fix/grid-sort-mixed-type-columns

Conversation

@Blankll

@Blankll Blankll commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Problem

The #171 sorting implementation resolves the comparison kind per cell (resolveSortKind on every comparison). On columns holding mixed primitives — routine on SQLite, whose dynamic typing mixes integers, booleans and strings in one column — this breaks two ways:

  • the comparator flips kind between passes → unstable order
  • resolveSortKind inspected only the left value → compare(a,b) !== -compare(b,a) → asymmetric comparator

Fix

Kind is now resolved once per column (resolveColumnKind):

  • the declared column type wins outright (integer → numeric, …)
  • without a usable declaration, the highest-precedence kind present in the column is used — number → boolean → date → string; strings are never date-sniffed
  • sortRowsByState resolves kinds per sorted column and reuses them across passes
  • everything else from feat(grid): client-side sorting for primitive result columns #171 is preserved: NULL-after-values ordering, non-primitive column exclusion, boolean/number/date coercers, stable ties

Test plan

  • gridSort.test.ts — 24 passed, incl. new cases: untyped number+string column sorts by one fixed kind; comparator symmetry on mixed columns; declared type wins over value kinds
  • vue-tsc --noEmit + eslint clean

@Blankll Blankll closed this Oct 8, 2026
@Blankll Blankll reopened this Oct 8, 2026
@Blankll
Blankll force-pushed the fix/grid-sort-mixed-type-columns branch from b388918 to 0286216 Compare October 8, 2026 16:09
@Blankll
Blankll marked this pull request as draft October 8, 2026 16:12
@Blankll
Blankll marked this pull request as ready for review October 8, 2026 16:12
@Blankll
Blankll force-pushed the fix/grid-sort-mixed-type-columns branch 3 times, most recently from dc8da67 to 97b3338 Compare October 8, 2026 16:35
Integrate the kind-precedence design into the #171 implementation.

Per-cell kind resolution (resolveSortKind on every comparison) breaks
two ways on columns holding mixed primitives — routine on SQLite:

- the comparator flips kind between passes, so order is unstable
- resolveSortKind inspected only the LEFT value, making
  compare(a,b) !== -compare(b,a) — an asymmetric comparator

Kind is now resolved once per column: the declared type wins outright;
without one, the highest-precedence kind present is used (number →
boolean → date → string; strings are never date-sniffed). NULL ordering,
non-primitive column exclusion and the coercers from #171 are unchanged.
@Blankll
Blankll force-pushed the fix/grid-sort-mixed-type-columns branch from 97b3338 to d520665 Compare October 8, 2026 16:42
The global AGENTS.md prefers const xxx = (...) => ... declarations; the
antfu preset's top-level-function rule enforced the opposite and blocked
the gridSort refactor. Turn the rule off — existing function
declarations stay as-is, new code follows AGENTS.md.
@Blankll
Blankll merged commit 86bded8 into master Oct 8, 2026
3 checks passed
@Blankll
Blankll deleted the fix/grid-sort-mixed-type-columns branch October 8, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant