I have a custom parser called agoSort
on a column with time difference values like "3 hours ago", "1 week ago", etc.
It's added using the headers
argument:
$(".data-table").tablesorter({
headers: {
1 : {
sorter: 'agoSort'
}
}
});
http://jsfiddle.net/chrisdillon/PGe6q/
All other columns use default sorting. The column order will change based on user selection (before document ready) so I need to be able to assign the custom parser after the table is rendered.
I tried <th class="{'sorter':'agoSort'}"
without args $(".data-table").tablesorter();
but no joy. http://jsfiddle.net/chrisdillon/LMHRA/
I know I can find the column with var agoColumn = $('.some-class').index();
.
Is there a way to do it?
If the column order changes, you can instead set the sorter using a class name (ref):
<th class="sorter-agoSort">Post Date</th>
If the column order changes after the table has initialized, use the updateAll
method to update the table cache.
As an aside, if you want to use a library for a more rich natural language date sort, try out something like sugar. Check out this demo