ChemPal Documentation - v1.6.0
    Preparing search index...

    Function puritySortingFn

    • 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. Reads grade ?? 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.

      Parameters

      • rowA: Row<Product>

        The first row to compare.

      • rowB: Row<Product>

        The second row to compare.

      Returns -1 | 0 | 1

      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;
      }