Skip to content
Source
Sign inSign up
TanStack/table

fix(table-core): compare equal values consistently in greaterThanOrEqualTo and lessThan #6607

Opendfedoryshchev(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/6607/headopened

Showing 3 changed files with 53 additions and 3 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/even-filters-compare.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/table-core': patch
+---
+​
+Make `filterFn_greaterThanOrEqualTo` and `filterFn_lessThan` (and the endpoints of `filterFn_between` / `filterFn_betweenInclusive`) treat values as equal using the same normalization as `filterFn_greaterThan`, so `30` equals `'30'`, two `Date`s with the same time are equal, and strings that differ only in case are equal.
16 additions and 3 deletionspackages/table-core/src/features/column-filtering/filterFns.tsModified
View file
@@ -216,7 +216,8 @@
/**
* Keeps rows whose value is greater than or equal to the filter value.
- * Delegates to the built-in greater-than and strict-equality comparisons.
+ * Equality uses the same normalization as greater-than, so `30` equals `'30'`
+ * and two `Date`s with the same time are equal.
export const filterFn_greaterThanOrEqualTo = constructFilterFn({
filter: (dataValue, filterValue) =>
@@ -487,12 +488,16 @@
return new Date(value).getTime()
​
-function compareGreaterThan(dataValue: any, filterValue: any): boolean {
+function compareValues(dataValue: any, filterValue: any): number {
const numericDataValue = dataValue == null ? 0 : +dataValue
const numericFilterValue = Number(filterValue)
​
if (!isNaN(numericFilterValue) && !isNaN(numericDataValue)) {
return numericDataValue > numericFilterValue