Wildcard in moment format
Wildcard in moment format

I am trying to sort a date format like this "01.05.2020 00:00-01:00" using Moment but I can't figure out how to ignore the "-01:00" part. I thought using something like ('DD.MM.YYYY HH:mm******') would work but it doesn't.
Here is the link to a test case:
https://jsfiddle.net/bgfehjmt/
I found a workaround to use ('DD.MM.YYYY HH:mm-ss:ss') but this is a very hacky solution.
https://jsfiddle.net/qb7k165h/
This discussion has been closed.
Answers
As far as I know the moment.js format method does not use wildcards. The second option seems to be the correct one to match your datetime format. The moment format() docs are here:
https://momentjs.com/docs/#/displaying/
To change the sorting to ignore the
-ss:ss
portion you will usecolumns.render
for the sort operation as described in the Orthogonal Data docs. For example:https://jsfiddle.net/rs3aehgq/
Kevin
The fiddle you posted does not sort correctly for me.
It looks correct to me:
Please describe what is incorrect or what you are expecting.
Kevin
Well you are sorting datetime in descending order in the picture.
So it should be:
01.05.2020 01:00
01.05.2020 00:00
30.04.2020 23:00
30.04.2020 22:00
And ascending should be the reverse of that.
As far as I can see from the docs you provided this only works if you get your data via ajax.
But i found another useful thing there in the "data-sort" attribute. I can just populate this in php and then I don't even need to use moment.
Yes, sorry not enough coffee. yet.
The behavior is not what I expected. It looks like the type detection runs have the orthogonal data 'display' operation runs instead of after the 'sort' operation. This can be seen in this example:
https://jsfiddle.net/d75fkzph/
@allan or @colin can tell us if this is incorrect configuration or expected behavior.
However if you have DOM sourced data you can use HTML5 attributes to set the
data-sort
attribute with the01.05.2020 01:00
portion. More info here. See this example:https://jsfiddle.net/hnqty3op/
Kevin
999/1000 times you want the
type
andsort
types to return the same thing. The type detection is primarily used by the sorting, so you want to make sure they get the same data.There are exceptions to the rule, and filtering can have its own type configuration, such as to handle HTML, but almost always you'd want to do
if (type === 'sort' || tyoe === 'type' ) { ...
.With that change the sorting works as does filtering without a complete value.
Allan
I see, with
tyoe === 'type'
you are influencing type detection with what you are using for sorting. I've seen this before bu t never understood it until now. Thanks!Kevin