Datetime-columnsorting with momentJS - different behaviour asc/desc needed
Datetime-columnsorting with momentJS - different behaviour asc/desc needed

Hello together, I am using the "Ultimate Date / Time sorting" (http://datatables.net/plug-ins/sorting/datetime-moment) to sort a datetime-column with momentJS.
It's working pretty fine, but I need to differentiate between asc/desc-ordering, but I can't do
types.order[ 'moment-'+format+'-asc' ] = function ( d ) {
//do something
};
types.order[ 'moment-'+format+'-desc' ] = function ( d ) {
//do something
};
instead of
types.order[ 'moment-'+format+'-pre' ] = function ( d ) {...
Is there a way to achieve that behaviour?
(What I try to do is that cells with a '-' (dash) are sorted to the bottom of the column not matter which direction)
This discussion has been closed.
Answers
Why not? It should be quite possible to remove the
-pre
method and then replace it with-asc
and-desc
that will perform the required actions for each option. Could you link to a page showing the problem perhaps?Out of interest, what is the different action? I've often considered removing that ability in the core and leaving only the
-pre
option as it adds a few extra KB to the library size!Allan
when I remove the
-pre
and replace it with-asc
,-desc
it jumps in, but the console.log (to check if the function got called) gets logged 7498 times!I have a column with dates and dashes '-' and the I want to sort the dashes always to the end of the list, so I return
So it does actually work, but you are concerned about the performance? This is exactly what the
-pre
option was designed for. It is basically a preformatter, so any calculations to format the date for sorting should be done in-pre
and then-asc
and-desc
which will be called a lot (as is the nature of sorting algorithms - which one exactly is used is defined by the browser being used, not DataTables).So what you could do is do the Moment parsing in
-pre
and then a trivial check to see if the value is an integer or not in the two sorting functions.See also the manual for details.
Allan