• Resolved sporulia

    (@sporulia)


    Hi – another question I’m afraid…
    I want my table to be sortable, with the initial view sorted by date, newest first.

    I’m installed the Data Tables sorting plugins from the tablepress.org homepage, and all the data in the table is formatted dd/mm/yyyy. After searching around on the tablepress and wp-table reloaded forums, I found 2 custom commands which seem relevant:

    when i used:
    "aaSorting": [[3,'desc']]
    that gave me the initial view sorted fine, biggest to smallest but it wasn’t recognising the column as containing dates (so eg 23/06/2003 would be shown above 01/06/2012). I couldn’t work out whether datatables was supposed to detect the data format automatically or not. Then I added another command:
    "aoColumnDefs": [ { "sType": "html", "aTargets": [ "column-3" ] } ]
    which gave me the column sorted by date. The only problem was that it was sorted oldest first, rather than newest first, and also it was not possible for the visitor to sort by other columns (I assume this comes from a Javascript error, probably putting two commands in without knowing the correct syntax).

    So what should I put in the custom commands box to get a sortable table, initially sorted by date, newest first?

    Thanks ever so much Tobias or anyone else who feels like helping!

    https://www.ads-software.com/extend/plugins/tablepress/

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

    (@tobiasbg)

    Hi,

    thanks for your question.

    If your date format is dd/mm/yyyy, you will actually need a TablePress Extension first, as that date format is not usable out of the box. Please install and activate the Extension from https://tablepress.org/extensions/datatables-sorting-plugins/

    After that, you should only need

    "aaSorting": [[3,'desc']]

    which will make the initial sort on the fourth (!) column (counting starts with 0 in the code).
    That other piece of code is totally unrelated to date sorting, so you can’t use that.

    Regards,
    Tobias

    Thread Starter sporulia

    (@sporulia)

    Thanks for your swift answer.
    I am using the extension, and the command you gave me is the one I was using before. However, it is still not recognising the date format, and so is sorting by the days instead of by the years. (ie on my list the 29/03/2004 is first on the list, and 01/05/2012 is at the bottom).

    Any other ideas about what else I could try? It was strange that using a wrong command did cause it to recognise the dates, although it didn’t sort them properly.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    can you please post the link to the page with the table?

    Regards,
    Tobias

    Thread Starter sporulia

    (@sporulia)

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the link.

    Ok, the sorting plugins are loaded, and the initial sort command is also used. However, the dates are not recognized automatically, so we’ll have to tell DataTables what format to use. Please extend your “Custom Commands” textfield to this:

    "aaSorting": [[3,'desc']], "aoColumnDefs": [ { "sType": "date-eu", "aTargets": [ 3 ] } ]

    Regards,
    Tobias

    Thread Starter sporulia

    (@sporulia)

    Thanks Tobias, it works perfectly!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    awesome! That’s great to hear ?? Thanks for the confirmation!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    Hi Tobias,

    also thank you from our side! Your command works perfectly!

    Cheers!

    DELUCKS

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    very nice. Great to hear that! ??

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    Hi guys,

    This is what i want on a table i use. Where do I add de code?

    “aaSorting”: [[3,’desc’]], “aoColumnDefs”: [ { “sType”: “date-eu”, “aTargets”: [ 3 ] } ]

    is it like this?[table id=2 datatables_columnfilter="true" datatables_counter_column="true" "aaSorting": [[2,'desc']], "aoColumnDefs": [ { "sType": "date-eu", "aTargets": [ 2 ] } ] /]

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi cajos1968,

    thanks for your question!

    No, this code does not belong in the Shortcode but in the “Custom Commands” textfield in the “Features of the DataTables JavaScript library” section (below the table input fields) on the “Edit” screen of the table.

    Regards,
    Tobias

    Ah found the spot!! Tablepress is great tool.

    Still struggling to sort my dates from latest to oldest. I also notice after punting code there the row numbers don’t work anymore.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    great to hear that you found the field and that you like the plugin! ??

    If this problem continues, please post a link to the page with the table, and I’ll take a look.
    Also, what row numbers do you mean here?

    Regards,
    Tobias

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for that! Can you please try again with the ColumnFilter activated? It might be possible that the internal JavaScript code of that is not compatible. ??

    Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Sorting by date with Data Tables sorting extension’ is closed to new replies.