Comments on: JQuery Tablesorter: List of Builtin Parsers/Sorters http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/ I will not fix your computer. Tue, 04 Aug 2020 22:34:33 +0000 hourly 1 https://wordpress.org/?v=4.7.26 By: Matt http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-280352 Fri, 12 Jun 2015 21:57:33 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-280352

I had this issue of how the sorter was handling dates along with blank values. Turns out the sorter code treats a blank cell as “Jan 1, 1970” (0 in javascript). What I ended up doing was updating the “shortDate” parser to handle blank dates as a constant specified in the config:

tablesorter: new
function () {

var parsers = [],
widgets = [];

this.defaults = {
cssHeader: “header”,
cssAsc: “headerSortUp”,
cssDesc: “headerSortDown”,
cssChildRow: “expand-child”,
sortInitialOrder: “asc”,
sortMultiSortKey: “shiftKey”,
sortForce: null,
sortAppend: null,
sortLocaleCompare: true,
textExtraction: “simple”,
parsers: {}, widgets: [],
widgetZebra: {
css: [“even”, “odd”]
}, headers: {}, widthFixed: false,
cancelSelection: true,
sortList: [],
headerList: [],
dateFormat: “us”,
decimal: ‘/\.|\,/g’,
onRenderHeader: null,
selectorHeaders: ‘thead th’,
debug: false,
treatBlankDateAs: “01/01/0001”
};

ts.addParser({
id: “shortDate”,
is: function (s) {
return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
}, format: function (s, table) {
var c = table.config;
if (s === “”) {
s = c.treatBlankDateAs;
}
s = s.replace(/\-/g, “/”);
if (c.dateFormat == “us”) {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, “$3/$1/$2”);
} else if (c.dateFormat == “uk”) {
// reformat the string in ISO format
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, “$3/$2/$1”);
} else if (c.dateFormat == “dd/mm/yy” || c.dateFormat == “dd-mm-yy”) {
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, “$1/$2/$3”);
}
return $.tablesorter.formatFloat(new Date(s).getTime());
}, type: “numeric”
});

Reply  |  Quote
]]>
By: Jack http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-22114 Fri, 04 May 2012 14:30:25 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-22114

Thanks for this post! The table sorter documentation is lacking (because I couldn’t use the class metadata tags, and that is the only method they document), but this is exactly what I needed.

Reply  |  Quote
]]>
By: Mike R http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-21034 Thu, 22 Dec 2011 16:17:07 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-21034

Sadly, “floating” has evidently been removed. In the 2.0 version I’m looking at, the current list is:

text
digit
currency
ipAddress
url
isoDate
percent
usLongDate
shortDate
time
metadata

Which doesn’t help me. Since I’m trying to get it to sort numerically formatted data (US Locale):

11
22,222
33

But since it cuts off everything after the comma, it sorts 22,222 above 34. Wrong. So, either I’ll have to extend w/ my own sorter or write a textExtractor that removes numeric formatting. Sigh.

Reply  |  Quote
]]>
By: Norbert http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-20973 Wed, 14 Dec 2011 13:03:55 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-20973

I agree that this information (the parsers/sorters list) should have been in the documentation.

Reply  |  Quote
]]>
By: Andrew http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-19305 Fri, 03 Jun 2011 16:40:09 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-19305

Is there a way to sort by day of week?

Reply  |  Quote
]]>
By: Adam http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-18794 Wed, 30 Mar 2011 16:41:18 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-18794

Hi all, I was wondering if anyone knew how to deal with IE 8 not properly sorting by digits when the column head is clicked. The first column is numerical with the column header text “ID”. Code sample below:

$(document).ready(function(){

$("#sortableTable")
.tablesorter({
headers:
{
0 : { sorter: "digit" }
},
widgets: ["zebra"]

})
});

The problem is, in Chrome and Firefox (on Windows 7) I can click on the “ID” column header and the sorting will toggle from ascending to descending (and back).
In IE8 (also Win 7) you can click all you like on the ID column header.

Any help appreciated, thanks.
Adam

Reply  |  Quote
]]>
By: Jason http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-18368 Fri, 28 Jan 2011 17:45:27 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-18368

Does anyone know if it’s possible to get tablesorter to correctly sort a column of the days of the week? At the moment it just lists them alphabetically. I’ve searched high and low for answers but the only references I’ve found are to force it to parse a column by date etc. as suggested here.

Any suggestions / advice would be greatly appreciated.

Thanks

Reply  |  Quote
]]>
By: Jessica http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-15580 Tue, 18 May 2010 15:31:58 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-15580

Thank you, Thank you, Thank you!

Reply  |  Quote
]]>
By: Todd http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-14311 Mon, 15 Feb 2010 15:05:58 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-14311

Great post – I had problems with the sorters too.

I want to have two header rows where :

1st row contains column totals
2nd Row contains column names

How can I prevent tablesorter from sorting when 1st row is clicked?

Reply  |  Quote
]]>
By: KJ http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-14292 Fri, 12 Feb 2010 11:51:10 +0000 http://www.terminally-incoherent.com/blog/2008/09/29/jquery-tablesorter-list-of-builtin-parserssorters/#comment-14292

Thanks for this. Helped me a great deal with a problem I had trying to sort an event listing by date. Couldn’t figure it out and it was doing my head in but this post saved the day for me.

Cheers!
KJ

Reply  |  Quote
]]>