WordPress.org

Forums

TablePress
[resolved] Date sorting issue with text (2 posts)

  1. mchiampa
    Member
    Posted 1 year ago #

    Hi Tobias,

    I love your plugin. Super clean and easy to use so thanks!

    I have a table that includes dates in the US format which sorts properly. Unfortunately I have some rows where the date is TBD and I am stuck as to what to do. I want these rows to sort as if they are the last date, since if they are TBD it means they are probably after the dates already in the table.

    If I type in "TBD" as text, it breaks the filtering for the dates. If I leave them blank, the rows are sorted as if the blank rows are 0 and thus come first.

    Can you think of a way to have these blank date rows sorted last?

    Not super serious but I figured it was worth asking.

    Thanks!

    http://wordpress.org/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for your question, and sorry for the trouble.

    I see what you are trying to do, but unfortunately, I don't have a solution to this yet :-( The date sorting is done via the external DataTables JS library, and modifying this sort behavior would require some extra coding to basically come up with a custom data format.

    Instead, I could imagine a (kind of hacky) workaround: Basically, you could duplicate the current column with the dates, and in the copy replace all "TBD" with something like "01/01/2099", i.e. a date in the far future. Then, it is possible to hide that column from the user, but tell the sorting algorithm to use the data in that column whenever a user wants to sort on the actual column with the dates (and "TBD"s). To make that work, you'd just have to add this to the "Custom Commands" textfield on the "Edit" screen of the table, after creating that copied columns as described:

    "aoColumnDefs": [ { "iDataSort": 1, "aTargets": [ 0 ] }, { "bVisible": false, "aTargets": [ 1 ] } ]

    This would tell the first column (indicated by the 0) to use the data from the second column (indicated by the first 1), while it would also hide the second column (indicated by the second 1 in the code). (Counting columns starts with 0 for this code.)

    Regards,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • TablePress
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.