Change default ordering?

Change default ordering?

ManOfWarManOfWar Posts: 2Questions: 1Answers: 0

Hey Guys,
I am pretty newbie when it comes to a lot of this stuff. I can not for the life of me figure out how to change the default ordering of my table. The first row is just a row of dates and I would like the newest dates to be at the top of the table not the bottom. Please help!

Answers

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945

    By default column 0 is initially sorted ascending. You could have configured column 0 to be hidden and the first column displayed is column 1 or something else. Column 0 would still, by default, be the initial sort. The initial sorting is configured using order. You can change the column to initially sort to the date column using order.

    Or it could be that the dates simply aren't being sorted properly. If this is the case then following the steps in this blog should fix the problem.
    https://datatables.net/blog/2014-12-18

    Please post any questions and your Datatables JS config if you still have issues.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi ManOfWar,

    Yep, as Kevin said, the order is the way to go. Take a look at this example here, this has the 5th column, which is a date, showing the newest at the top. So, for you, just change that order column to be 0.

    Cheers,

    Colin

  • ManOfWarManOfWar Posts: 2Questions: 1Answers: 0

    Hey Guys,
    Thanks for taking the time to answer my question. My biggest issue with everything you said is that I have no idea where ti input any of that information that you gave. Couldnt figure out for the life of me where to change 1 to 0. I did happen to stumble on this in the readme.txt file that came with the plugin and managed to solved the issue.

    " Some DataTables options need to be given JavaScript array literals, such as in the case of the DataTables order option, which controls the initial sort order for a table. However, using square brackets ([ and ]) inside a shortcode confuses the WordPress parser, so these characters must be URL-escaped (into %5B and %5D, respectively). Suppose you want your table to be sorted by the second column in descending order (instead of the first column in ascending order, which is the default). You need to supply a 2-dimensional array such as [[ 1, "desc" ]] to DataTable's order option (column counting begins at 0). In a shortcode, with the square brackets URL-escaped, this becomes:

    [gdoc key="ABCDEFG" datatables_order='%5B%5B 2, "desc" %5D%5D'] "
    

    Who would have thought....

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Yes - that is very not obvious. But not really something that we can document on this site since it is specific to WordPress, and DataTables is a generic library that will run in any web browser, regardless of what CMS software is being used.

    It sounds like you are using a plug-in for WordPress, and it was documented in whatever plug-in you were using.

    Allan

This discussion has been closed.