• Resolved gtexeira

    (@gtexeira)


    A table is not being sorted by date in descending order, ie Most current to oldest date.

    I am importing a CSV file with a date format of yyyy-mm-dd. The dates are in column 1. Here is a sample:
    2018-03-18,22,2,2,3,0,0,0,1,0,0,2,32

    I have also included the following code in the custom commands field:

    order:[[0,’desc’]],columnDefs:[{type:’date’,targets:[0]}]

    I also have the line checked in Use the following features of the DataTables JavaScript library with this table

    The TablePress plugin versions installed are:
    1. TablePress Version 1.9.2
    2. TablePress Extension Version 1.0
    3. TablePress Extension: Table Auto Update Version 1.2

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    This all looks correct to me. Unfortunately, to check this out, I’d need to access the actual page with the table… Can you maybe make that page available?

    Regards,
    Tobias

    Thread Starter gtexeira

    (@gtexeira)

    I don’t have the ability to open the firewall rules.

    Here is what I see from the dev tools report.

    Uncaught SyntaxError: Invalid or unexpected token

    $(‘#tablepress-7’).dataTable({“order”:[],”orderClasses”:false,”stripeClasses”:[“even”,”odd”],”paging”:false,”searching”:false,”info”:false,order:[[0,’desc’]],columnDefs:[{type:’date’,targets:[0]}]});

    • This reply was modified 6 years ago by gtexeira.
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ah, ok, so you are getting an actual JS syntax error opposed to the sorting just not working.

    Can you please check if you are using actual upright double and single quotation marks (" and ') in the “Custom Commands” text field? The forum software here uses typographically different ones ( and ) which would cause trouble.

    Regards,
    Tobias

    Thread Starter gtexeira

    (@gtexeira)

    hmm.

    I updated the “custom commands” field with double quotes:

    “order”: [ [ 0, “desc” ] ], “columnDefs”: [ { “type”: “date”, “targets”: [ 0 ] } ]

    still I have the report showing the oldest at the top.
    however the console now does not show an error.

    The csv file looks like:

    we,a,b,c,d,e,f,g,h,i,j,k,l
    2018-03-18,22,2,2,3,0,0,0,1,0,0,2,32
    2018-03-19,159,9,9,2,0,0,0,2,0,0,16,197
    2018-03-20,132,4,3,6,0,1,1,0,1,1,12,161

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    does the order change if you use asc instead of desc in the first part of the command?

    For this date format (yyyy-mm-dd), you could actually also use the normal string sorting, i.e.

    "order": [ [ 0, "desc" ] ], "columnDefs": [ { "type": "string", "targets": [ 0 ] } ]
    

    Does that work?

    Regards,
    Tobias

    Thread Starter gtexeira

    (@gtexeira)

    I copied and pasted your code above and it did not work with ASC and DESC. I also did not get any errors with the page inspector. Is there a php source file that I need to update?

    I also discovered that the sorting only works when I enable “Enable sorting of the table by the visitor.” If I disable it, it goes back to the original sort.

    • This reply was modified 6 years ago by gtexeira.
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    correct, all this only works if the “Sorting” checkbox is enabled on the “Edit” screen, as the “Custom Command” depends on this feature.

    If you don’t want the table to be user-sortable, the “Custom Command” is not the right way. You could then either one-time sort the table on the “Edit” screen (via the sort arrow icons in the column header cell), or use the TablePress Extension from https://tablepress.org/extensions/table-row-order/ to achieve a pre-sorting when the table is shown to the visitor. As your date format can also be sorted as strings, both of these methods should work.

    Regards,
    Tobias

    Thread Starter gtexeira

    (@gtexeira)

    Hi Tobias,

    Thank you for clarifying the expected sorting functionality when using the “Custom Command” field within the TablePress edit screen.

    The TablePress Extension from https://tablepress.org/extensions/table-row-order/ was the way to go, instead. This works as desired for me.

    Thanks for your help.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

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

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Unable to Sort Date’ is closed to new replies.