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

    Function priceSortingFn

    • Custom sorting function for price comparison between two product rows. Compares the USD prices of products (falling back to raw price) and returns a sort order value.

      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: { price: priceSortingFn }, ... });
      // A row with usdPrice 29.99 sorts after one with 9.99.
      export function priceSortingFn(rowA: Row<Product>, rowB: Row<Product>) {
      const a = rowA.original.usdPrice ?? rowA.original.price ?? 0;
      const b = rowB.original.usdPrice ?? rowB.original.price ?? 0;
      return a > b ? 1 : a < b ? -1 : 0;
      }