I'm using JQuery Tablesorter version 2.17.8 to sort a table
I've created a custom parser to sort a date, followed by a time, followed by an optional string.
The parser looks like this:
$.tablesorter.addParser({
id: "datetime",
is: function (s) {
return /\d{2}\-\d{2}\-\d{2}\s\d{2}:\d{2}(door \w+)?/.test(s);
}, format: function (s) {
arr = s.split(/[\s\-:]/);
if(arr[0] == "") // table column is empty
timestamp = null;
else {
// Month is zero-indexed so subtract one from the month inside the constructor
date = new Date(Date.UTC('20' + arr[2], arr[1] - 1, arr[0], arr[3], arr[4])); // Y M D H M
timestamp = date.getTime();
}
console.log(timestamp);
return timestamp;
}, type: "numeric"
});
Example data of the table column to be sorted:
- 30-04-14 09:55
- 30-04-14 14:11 door I1
- Empty cell
The parser works as intended but I want the empty cells to be sorted to the bottom and that doesn't seem to work.
I placed this in my PHP file:
<script type="text/javascript">
{literal}
$(document).ready(function()
{
$("#betalingen").tablesorter( {
headers: {
5 : { sorter: false } }, // disable sorting for column #5
widgets: ["saveSort", "zebra"], // apply alternating row coloring
sortList: [[2,0]], // initial sorting order for Date column = ascending (0)
emptyTo: 'bottom' // empty cells are always at the bottom
}
);
} );
{/literal}
</script>
Note that I've tried every option here: http://mottie.github.io/tablesorter/docs/example-option-sort-empty.html
And when I remove my custom parser (and let Tablesorter figure out a parser), it sorts the empty cells to the bottom as intended but obviously the column isn't sorted correctly.
Anyone knows what is going on here?