in my react.js ant.design project I am trying to implement table range filtering based on 2 date pickers: for start date and end date. I inserted them into filter drop down, but when I hit the search
button, I get an error sayng that values.some is not a function
.
Example you may see HERE
The goal is to send to backend for searching an array of 2 dates: start date and end date. I suppose it is sending a moment.js
object there which is should be converted to string somehow, but I dont know where to do that. Any ideas how to fix it would be wele
in my react.js ant.design project I am trying to implement table range filtering based on 2 date pickers: for start date and end date. I inserted them into filter drop down, but when I hit the search
button, I get an error sayng that values.some is not a function
.
Example you may see HERE
The goal is to send to backend for searching an array of 2 dates: start date and end date. I suppose it is sending a moment.js
object there which is should be converted to string somehow, but I dont know where to do that. Any ideas how to fix it would be wele
- Any code would be better to view your exact problem – Krina Soni Commented Feb 13, 2020 at 12:03
- codesandbox.io/s/confident-swartz-veucu – Masha Commented Feb 13, 2020 at 12:04
- Any update? Still not able to filter by date range. – Hudson Medeiros Commented Sep 8, 2020 at 17:41
3 Answers
Reset to default 5Change the way on how you pass the values to setSelectedKeys function, the setSelectedKeys function accepts an array as the value.
So in order for this to work. Change your code into this.
onChange={e => setSelectedKeys([e.format("DD.MM.YYYY")])}
Also you must handle the on clear event of the datepicker to avoid passing null value to setSelectedKeys function.
onChange={e => setSelectedKeys(e !== null ? [e.format("DD.MM.YYYY")] : [])}
Your search function is not getting exact values of dates selected - selectedKeys[0], it is only getting latest selected date. Try to console it and check.
Solution to problem can be done through state as whatever you select as startDate and endDate, get those values in search function and pass it to API/Backend.
As angelo pointed out
setSelectedKeys function accepts an array as the value.
-> but his solution doesn't consider the upperborder of the interval.
As Krina Soni Pointed out
Your search function is not getting exact values of dates selected - selectedKeys[0], it is only getting latest selected date.
-> You will always just get one date.
Easiest workaround i found is to concat startdate and enddate values as strings and put it as one item into the array. Unwrap it again with split in your filter logic function. I solved it that way.