Last active
February 25, 2020 00:09
-
-
Save Blezzoh/34e3717738ed79beac06f4ed992077a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date.prototype.isValid = function() { | |
// An invalid date object returns NaN for getTime() and NaN is the only | |
// object not strictly equal to itself. | |
// eslint-disable-next-line | |
return this.getTime() === this.getTime(); | |
}; | |
const filterTypes = { | |
year: (rows, id, filterValue) => { | |
return rows.filter(row => { | |
const rowValue = row.values[id]; | |
return rowValue !== undefined && | |
Number(filterValue) && | |
new Date(rowValue) && | |
new Date(rowValue).isValid() | |
? new Date(rowValue).getFullYear() === Number(filterValue) | |
: true; | |
}); | |
}, | |
//default | |
text: (rows, id, filterValue) => { | |
return rows.filter(row => { | |
const rowValue = row.values[id]; | |
return rowValue !== undefined | |
? String(rowValue) | |
.toLowerCase() | |
.startsWith(String(filterValue).toLowerCase()) | |
: true; | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment