Another brilliant little bit of code to complement empty() is isBlank():
function isBlank(str) { return (!str || /^\s*$/.test(str)); }
Dominic Myers writes about all sorts of stuff to do with HTML, CSS, JavaScript and a fair chunk of self-indulgent stuff. Thoughts and opinions are all his own, and nothing to do with any employer.
I use DataTables a lot, I think they're brilliant and I'm slowly getting to understand their intricacies. Anyway, I had a need to sort a column by month name only so I came up with this:
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; jQuery.fn.dataTableExt.oSort['month-name-asc'] = function (x, y) { var xPos, yPos; jQuery.each(monthNames, function (k, v) { if (x == v) xPos = k; if (y == v) yPos = k }); return ((xPos < yPos) ? -1 : ((xPos > yPos) ? 1 : 0)); }; jQuery.fn.dataTableExt.oSort['month-name-desc'] = function (x, y) { var xPos, yPos; jQuery.each(monthNames, function (k, v) { if (x == v) xPos = k if (y == v) yPos = k }); return ((xPos > yPos) ? -1 : ((xPos < yPos) ? 1 : 0)); };
Simply add "sType": "month-name"
to the column def and away you go!