I want to filter the Date, but my problem is that I have to give the Date unformatted to the React-Table because of the sort-Function. So I define my Column like this:
{
Header: "ORDER_DATE",
accessor: "creationDate",
sortable: true,
Cell: ({value})=>{return format(new Date(value),'dd.MM.yyyy')}
}
I give the Date in this format to the Column: "2021-09-20T00:00:00+0000". Adding the format Function to the Cell-Property, means that I write the unformatted Date to the Table but it will be displayed formatted. Now I have my globalFilter where I can filter with an InputField. The formatted Date has this format: dd.MM.yyyy and unformatted it is like this: yyyy-mm-dd. My idea was to split and convert it. Here my code
const formatWhenDate = (value) => {
return value.split(".").reverse().join("-");
}
<input
id="test"
onChange={(e) =>{ setInput(e.target.value);setFilter(formatWhenDate(e.target.value));}}
/>
It also works, but only when I enter the full month and Year because I can´t change for example: 17.0 to 0X-17 (X is a placeholder for a empty value).
Does know somebody how to handle it in relation to the React-Table or does somone could edit my function(formatWhenDate) so that also dates with not full month(11.0 intead of 11.09) or years(20 instead of2021 will be filtered correctly?