1 if rowA ranks after rowB, -1 if before, 0 if equal.
useReactTable({ sortingFns: { puritySortingFn }, ... });
// "ACS Grade" (99.8) sorts after "Technical Grade" (90), which sorts after "95%".
export function puritySortingFn(rowA: Row<Product>, rowB: Row<Product>) {
const a = sortablePurityGrade(rowA.original.grade ?? rowA.original.purity ?? '');
const b = sortablePurityGrade(rowB.original.grade ?? rowB.original.purity ?? '');
return a > b ? 1 : a < b ? -1 : 0;
}
TanStack sorting comparator that orders two product rows by purity. The column mixes two kinds of value — a chemical grade (
"ACS Grade") and a percentage ("≥99.8%") — so both are put on one numeric scale by sortablePurityGrade. Readsgrade ?? purity, the same precedence the purity column's accessor uses, so the sort order matches what the cell shows. A row with neither (or an unrecognized grade, e.g."Ungraded") sorts as 0.