Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question.

    That date format is unfortunately not built-in into the DataTables JavaScript library (from http://www.datatables.net), that TablePress uses for the sorting.

    It could in theory be added by custom coding, but unfortunately I don’t really know how that would have to look like 🙁 Sorry.

    Can you maybe switch to another date format like

    dd.mm.yyyy

    or

    dd/mm/yyyy

    ?

    Regards,
    Tobias

    Thread Starter Gunde

    (@gunde)

    Hi

    Unfortunately I can’t (or I just can’t figure it out) switch the format because the date are all scraped from WP blogs “lastbuilddate”

    I’ll sleep on it..again

    Thx for the fast response

    /Gunde

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, ok. I see…
    You might try to contact the developer of the DataTables library at http://www.datatables.net. Maybe he can give you the necessary JavaScript code, or at least offer to create it on a professional basis.

    Best wishes,
    Tobias

    Thread Starter Gunde

    (@gunde)

    Hi Tobis

    I’ve managed to change the format: dd/mmm/yyyy (stil not sortable)

    I’ve look around datatables.net and found some code:

    // Override default implementation for date sorting
    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
        "date-uk-pre": function ( a ) {
            var ukDatea = jQuery(a).text().split('-');
            if(ukDatea.length==2){
                var month = ukDatea[0];
            }else{
                month = ukDatea[1];
            }
            if(month=="jan" || month=="Jan"){month=01;}
            else if(month=="feb" || month=="Feb"){month=02;}
            else if(month=="mar" || month=="Mar"){month=03;}
            else if(month=="apr" || month=="Apr"){month=04;}
            else if(month=="may" || month=="May"){month=05;}
            else if(month=="jun" || month=="Jun"){month=06;}
            else if(month=="jul" || month=="Jul"){month=07;}
            else if(month=="aug" || month=="Aug"){month=08;}
            else if(month=="sep" || month=="Sep"){month=09;}
            else if(month=="oct" || month=="Oct"){month=10;}
            else if(month=="nov" || month=="Nov"){month=11;}
            else{month=12;}
            if(ukDatea.length==2){
                return (ukDatea[1] + month) * 1;
            }else{
                return (ukDatea[2] + month + ukDatea[0]) * 1;
            }
        },
    
        "date-uk-asc": function ( a, b ) {
            console.log(a+" "+b);
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },
    
        "date-uk-desc": function ( a, b ) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        }
    });

    Link

    Is it possible to implement the code in the jQuery of the Tablepress sorting extention?!?

    /Gunde

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, very cool. Nice find!

    To use that in TablePress, I suggest to simply append that code to the files jquery.datatables.sorting-plugins.js and jquery.datatables.sorting-plugins.min.js
    After that, the sorting algorithms will be loaded. You will then just have to apply them to the desired column, by adding the following to the “Custom Commands” textfield in the “Features of the DataTables JavaScript library” section on the “Edit” screen of the table:

    "aoColumnDefs": [ { "sType": "html", "aTargets": [ "column-4" ] } ]

    Change the “column-4” to the correct column number, i.e. change the 4 to the number of the column that contains the dates in the new format.

    Regards,
    Tobias

    Thread Starter Gunde

    (@gunde)

    Hi

    Well it works like a charm, sorting dd/mm/yy , dd/mmm/yyyy and dd/mm/yyyy.

    But turns out the WP scraper that I use creates blank spaces before and after the output, sow I can’t sort my list. I found another scraper that nearly does the job. (It don’t allow regex before output)
    Is it possible to run regex inside the table?

    /Gunde

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    so, you mean that your dates turn up like

    " 02 Jan 2103 "

    instead of

    "02 Jan 2103"

    (without the quotation marks “, but with the spaces as in the first case?
    And due to that, the sorting with the code you found is not working?
    Well, you could simply remove the spaces in the sorting algorithm, so that the sorting works. Just replace the line

    var ukDatea = jQuery(a).text().split('-');

    with

    var ukDatea = jQuery(a).text();
    ukDatea = jQuery.trim( ukDatea );
    ukDatea = ukDatea.split('-');

    Regards,
    Tobias

    Thread Starter Gunde

    (@gunde)

    Hi

    In the soucecode it’s like this:
    " 02 Jan 2103 "

    On the page it’s like this:
    "02 Jan 2103"

    Really weird.

    The scraper plug-in seems not to be updated any more so I’ll try the other one I found that’s up-to-date (but with out any functions).

    The .trim didn’t work, but thanks anyway.

    /Gunde

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, that’s too bad. Sorry about that 🙁
    I hope that you can find a solution to your problem…

    Best wishes,
    Tobias

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sorting by dateformat’ is closed to new replies.