admin管理员组文章数量:1331622
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.
本文标签: javascriptreactjs ant design range filter with start and end dates errorStack Overflow
版权声明:本文标题:javascript - react.js ant design range filter with start and end dates error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742233386a2437632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论