ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function quantitySortingFn

    • TanStack sorting comparator that orders two product rows by their normalized baseQuantity (a missing quantity 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 > rowB, -1 if rowA < rowB, 0 if equal.

      useReactTable({ sortingFns: { quantity: quantitySortingFn }, ... });
      // A row with baseQuantity 500 sorts after one with 100.
      export function quantitySortingFn(rowA: Row<Product>, rowB: Row<Product>) {
      const a = rowA.original.baseQuantity ?? 0;
      const b = rowB.original.baseQuantity ?? 0;
      return a > b ? 1 : a < b ? -1 : 0;
      }