Skip to content

Commit

Permalink
fix(table): allow filtering on false values and sorting date objects. F…
Browse files Browse the repository at this point in the history
…ixes #2485 (#2544)
  • Loading branch information
tmorehouse authored Feb 13, 2019
1 parent 50c6b2d commit 79315d6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ function sanitizeRow(row) {
// becomes
// 'one 3 2 zzz 10 12 11'
function toString(v) {
if (!v) {
if (typeof v === 'undefined' || v === null) {
return ''
}
if (v instanceof Object) {
if (v instanceof Object && !(v instanceof Date)) {
// Arrays are also object, and keys just returns the array indexes
// Date objects we convert to strings
return keys(v)
.sort() /* sort to prevent SSR issues on pre-rendered sorted tables */
.map(k => toString(v[k]))
Expand All @@ -64,7 +65,11 @@ function recToString(row) {
function defaultSortCompare(a, b, sortBy) {
a = get(a, sortBy, '')
b = get(b, sortBy, '')
if (typeof a === 'number' && typeof b === 'number') {
if (
(a instanceof Date && b instanceof Date) ||
(typeof a === 'number' && typeof b === 'number')
) {
// Special case for comparing Dates and Numbers
return (a < b && -1) || (a > b && 1) || 0
}
return toString(a).localeCompare(toString(b), undefined, {
Expand Down

0 comments on commit 79315d6

Please sign in to comment.