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