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
-premethod and then replace it with-ascand-descthat 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
-preoption as it adds a few extra KB to the library size!Allan
when I remove the
-preand replace it with-asc,-descit 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
-preoption was designed for. It is basically a preformatter, so any calculations to format the date for sorting should be done in-preand then-ascand-descwhich 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
-preand 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