Search code examples
tablesorter

Sort on non visible table data


I have a table where one of the columns shows a "Last modified" time stamp. This time stamp is in human readable form e.g. "5 minutes ago" and not in a date time format. The problem is that this does not sort well, since obviously I want the table to sort from the absolute time stamp when I sort on that column.

Is there a way to force talbesorter to use a data tag attribute to sort on instead? E.g. 5 minutes ago

Using motties tablesorter fork http://mottie.github.io/tablesorter/docs/#Support


Solution

  • Change the textAttribute option to match the data-attribute being used as the time stamp. If the date format matches a parser then it will be detected automatically.

    Alternatively, you could use the sugar.js library to translate the human readable date into a date object - see this demo.