Rant: Datatable/Column should handle string to date conversions for filtering. #2483
Unanswered
SolidAnonDev
asked this question in
PrimeReact
Replies: 1 comment 4 replies
-
I guess what it comes down to is you can NOT sort dates as "strings" logically so it has to be a Date object for sort ascending and descending to know if one date is before or after another. Take for example these strings in
As strings these would sort ascending...
Which is just clearly incorrect. And since date strings in countries can literally be any flavor like "mm-dd" or "yyyy-dd-mm" using |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am a little confused in general as to why the decision is made that in order for date filtering to be successful on a column filter, the incoming data has to have an instance of JavaScript Date. The docs themselves depict the mapping of the date fields in incoming data to Javascript Date instances. If there's some way around this I would like to know.
This is confusing to me for two reasons:
any
or plain JS everywhere like the docs do, you likely have atype
that maps to your database entity. Because the data cannot come in from the server as a Date, your type will likely contain the date field as a typescriptstring
type..map
the data like the docs show, however, this changes your type if you need to use the row data from the Datatable. It is no longer your original type, it is your type with a converted date field.Here's an example.
I do a lot of abstractions like the below..
Given this type:
Let's say I have a scenario where I am using the datatable as a 'selection interface' of sorts. THe user needs to select a MyEntity from the list and the datatable wrapper below provides a repeatable interface to both load the data, and allow a selection that is provided to the parent component via props:
If I want to filter on date however, I have to first map the data to convert the date field into a javscript date
This results in a problem, because my parent component is asking for MyEntity, not the result of mapping MyEntity to now have a
Date
instance instead of a string.I either have to change my type entirely, have two separate types, or convert the type back to the original before passing it to the parent, because the parent needs the original type, not the type + date conversion.
I don't see how it is a smart choice to require this conversion pre-filtering. It doesn't cause a problem if you're not trying to filter on date, but it causes kind of a big problem the second you want to filter on a date column.
Futhermore, this results in the necessity to map potentially 1000's of rows of data, rather than just providing the incoming data to the table without the map operation. This doesn't seem optimal to me at all.
Beta Was this translation helpful? Give feedback.
All reactions