diff --git a/README.markdown b/README.markdown
index 10375d51..8f462b28 100644
--- a/README.markdown
+++ b/README.markdown
@@ -28,6 +28,14 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs
View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt).
+#### Version 2.0.23 (2011-10-18)
+
+* Changed the `dateFormat` option:
+ * The settings are now "mmddyyyy", "ddmmyyyy", and "yyyymmdd".
+ * Changed the date separator to include any of the following: slash, dash, period, comma, space(s) or tab.
+ * The date format parser will only work with a four digit year.
+ * Added a [demo page](http://mottie.github.com/tablesorter/docs/example-option-date-format.html).
+
#### Version 2.0.22.1 (2011-10-15)
* Updated the stickyHeaders widget
diff --git a/changelog.txt b/changelog.txt
index eda111ca..a83e53d0 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,5 +1,14 @@
TableSorter Change Log
+Version 2.0.23 (2011-10-18)
+============================
+
+* Changed the `dateFormat` option:
+ * The settings are now "mmddyyyy", "ddmmyyyy", and "yyyymmdd".
+ * Changed the date separator to include any of the following: slash, dash, period, comma, space(s) or tab.
+ * The date format parser will only work with a four digit year.
+ * Added a [demo page](http://mottie.github.com/tablesorter/docs/example-option-date-format.html).
+
Version 2.0.22.1 (2011-10-15)
============================
diff --git a/docs/example-option-date-format.html b/docs/example-option-date-format.html
new file mode 100644
index 00000000..464cd87d
--- /dev/null
+++ b/docs/example-option-date-format.html
@@ -0,0 +1,150 @@
+
+
+
+
+ jQuery plugin: Tablesorter 2.0 - Changing the date format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Set the date format. Here are the available options:
+
"mmddyyyy"
+
Set the date format. Here are the available options. Modified in version 2.0.23.
-
"us" (default) - "mm-dd-yyyy" or "mm/dd/yyyy"
-
"uk" - "dd-mm-yyyy" or "dd/mm/yyyy"
-
"dd/mm/yy" or "dd-mm-yy" - Sort by short year (it appears to sort by day first, not the year)
+
"mmddyyyy" (default)
+
"ddmmyyyy"
+
"yyyymmdd"
+ In previous versions, this option was set as "us", "uk" or "dd/mm/yy". This option was modified to better fit needed date formats. It will only work with four digit years!
+
+ The sorter should be set to "shortDate" and the date format can be set in the "dateFormat" option or set for a specific columns within the "headers" option.
+ See the demo page to see it working.
+
$(function(){
+ $("table").tablesorter({
+
+ dateFormat : "mmddyyyy", // default date format
+
+ // or to change the format for specific columns,
+ // add the dateFormat to the headers option:
+ headers: {
+ 0: { sorter: "shortDate" }, // "shortDate" with the default dateFormat above
+ 1: { sorter: "shortDate", dateFormat: "ddmmyyyy" }, // day first format
+ 2: { sorter: "shortDate", dateFormat: "yyyymmdd" } // year first format
+ }
+
+ });
+});
@@ -551,7 +574,8 @@
// Sort the fifth column by date (e.g. mm/dd/yyyy if the date format is "us")
4: { sorter: "shortDate" },
- // See example 3: lock the sort order - this option will not work if added as metadata
+ // See example 3: lock the sort order
+ // this option will not work if added as metadata
5: { lockedOrder: "asc" },
// See Example 4: Initial sort order direction of seventh column
@@ -819,7 +843,9 @@ $(function(){
@@ -864,7 +890,9 @@ $(function(){
It does not work the same as "update" in that it only adds rows, it does not remove them.
Also, use this method to add table rows while using the pager plugin. If the "update" method is used, only the visible table rows continue to exist.
// Add multiple rows to the table
- var $row = $('<tr><td>Inigo</td><td>Montoya</td><td>34</td><td>$19.99</td><td>15%</td><td>Sep 25, 1987 12:00PM</td></tr>');
+ var row = '<tr><td>Inigo</td><td>Montoya</td><td>34</td>' +
+ '<td>$19.99</td><td>15%</td><td>Sep 25, 1987 12:00PM</td></tr>',
+ $row = $(row);
$('table')
.find('tbody').append($row)
.trigger('addRows', [$row]);
@@ -929,7 +957,8 @@ $(table)
$("td.discount").click(function(){
// randomize a number
- var discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' + ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
+ var discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' +
+ ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
$(this).text(discount);
// update the table, so the tablesorter plugin knows its value
diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js
index 268b9c9b..0b9e8982 100644
--- a/js/jquery.tablesorter.js
+++ b/js/jquery.tablesorter.js
@@ -1,6 +1,6 @@
/*
* TableSorter 2.0 - Client-side table sorting with ease!
-* Version 2.0.22
+* Version 2.0.23
* @requires jQuery v1.2.3
*
* Copyright (c) 2007 Christian Bach
@@ -99,7 +99,7 @@
cancelSelection: true,
sortList: [],
headerList: [],
- dateFormat: "us",
+ dateFormat: "mmddyyyy", // other options: "ddmmyyy" or "yyyymmdd"
onRenderHeader: null,
selectorHeaders: 'thead th',
tableClass : 'tablesorter',
@@ -243,8 +243,7 @@
/** Add the table data to main data array */
c = $(b.rows[i]);
cols = [];
- // if this is a child row, add it to the last row's children and
- // continue to the next row
+ // if this is a child row, add it to the last row's children and continue to the next row
if (c.hasClass(table.config.cssChildRow)) {
cache.row[cache.row.length - 1] = cache.row[cache.row.length - 1].add(c);
// go to the next for loop
@@ -252,7 +251,7 @@
}
cache.row.push(c);
for (j = 0; j < totalCells; ++j) {
- cols.push(parsers[j].format(getElementText(table.config, c[0].cells[j], j), table, c[0].cells[j]));
+ cols.push(parsers[j].format(getElementText(table.config, c[0].cells[j], j), table, c[0].cells[j], j));
}
cols.push(cache.normalized.length); // add position for rowCache
cache.normalized.push(cols);
@@ -650,11 +649,9 @@
config.sortList.push([i, this.order]);
// multi column sorting
} else {
- // the user has clicked on an all
- // ready sortet column.
+ // the user has clicked on an already sorted column.
if (isValueInArray(i, config.sortList)) {
- // revers the sorting direction
- // for all tables.
+ // reverse the sorting direction for all tables.
for (j = 0; j < config.sortList.length; j++) {
s = config.sortList[j];
o = config.headerList[s[0]];
@@ -918,21 +915,21 @@
});
ts.addParser({
- id: "shortDate",
+ id: "shortDate", // "mmddyyyy", "ddmmyyy" or "yyyymmdd"
is: function(s) {
- return (/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/).test(s);
+ // testing for ####-####-#### - so it's not perfect
+ return (/\d{1,4}[\/\-\,\.\s+]\d{1,4}[\/\-\.\,\s+]\d{1,4}/).test(s);
},
- format: function(s, table) {
- var c = table.config;
- 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");
+ format: function(s, table, cell, cellIndex) {
+ var c = table.config,
+ format = (c.headers && c.headers[cellIndex]) ? c.headers[cellIndex].dateFormat || c.dateFormat : c.dateFormat; // get dateFormat from header or config
+ s = s.replace(/\s+/g," ").replace(/[\-|\.|\,|\s]/g, "/");
+ if (format === "mmddyyyy") {
+ s = s.replace(/(\d{1,2})\/(\d{1,2})\/(\d{4})/, "$3/$1/$2");
+ } else if (format === "ddmmyyyy") {
+ s = s.replace(/(\d{1,2})\/(\d{1,2})\/(\d{4})/, "$3/$2/$1");
+ } else if (format === "yyyymmdd") {
+ s = s.replace(/(\d{4})\/(\d{1,2})\/(\d{1,2})/, "$1/$2/$3");
}
return $.tablesorter.formatFloat(new Date(s).getTime());
},
diff --git a/js/jquery.tablesorter.min.js b/js/jquery.tablesorter.min.js
index cbbd8c03..b4c80a6e 100644
--- a/js/jquery.tablesorter.min.js
+++ b/js/jquery.tablesorter.min.js
@@ -1,8 +1,7 @@
/*
* TableSorter 2.0 - Client-side table sorting with ease!
-* Version 2.0.22 Minified using http://dean.edwards.name/packer/
+* Version 2.0.23 Minified using http://dean.edwards.name/packer/
* Copyright (c) 2007 Christian Bach
*/
-(function($){$.extend({tablesorter:new function(){var g=[],widgets=[],tbl;this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:false,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",onRenderHeader:null,selectorHeaders:'thead th',tableClass:'tablesorter',debug:false};function log(s){if(typeof console!=="undefined"&&typeof console.debug!=="undefined"){console.log(s)}else{alert(s)}}function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms")}this.benchmark=benchmark;function getElementText(a,b,c){var d="",te=a.textExtraction;if(!b){return""}if(!a.supportsTextContent){a.supportsTextContent=b.textContent||false}if(te==="simple"){if(a.supportsTextContent){d=b.textContent}else{if(b.childNodes[0]&&b.childNodes[0].hasChildNodes()){d=b.childNodes[0].innerHTML}else{d=b.innerHTML}}}else{if(typeof(te)==="function"){d=te(b)}else if(typeof(te)==="object"&&te.hasOwnProperty(c)){d=te[c](b)}else{d=$(b).text()}}return d}function getParserById(a){var i,l=g.length;for(i=0;i").each(function(a){this.column=header_index[this.parentNode.rowIndex+"-"+this.cellIndex];this.order=formatSortingOrder(checkHeaderOrder(b,a));this.count=this.order;if(checkHeaderMetadata(this)||checkHeaderOptions(b,a)||$(this).is('.sorter-false')){this.sortDisabled=true}this.lockedOrder=false;lock=checkHeaderLocked(b,a);if(typeof(lock)!=='undefined'&&lock!==false){this.order=this.lockedOrder=formatSortingOrder(lock)}if(!this.sortDisabled){$th=$(this).addClass(c.cssHeader);if(c.onRenderHeader){c.onRenderHeader.apply($th,[a])}}c.headerList[a]=this});if(c.debug){benchmark("Built headers:",time);log($tableHeaders)}return $tableHeaders}function checkCellColSpan(a,b,d){var i,cell,arr=[],r=a.tHead.rows,c=r[d].cells;for(i=0;i1){arr=arr.concat(checkCellColSpan(a,b,d++))}else{if(a.tHead.length===1||(cell.rowSpan>1||!r[d+1])){arr.push(cell)}}}return arr}function isValueInArray(v,a){var i,l=a.length;for(i=0;i');$("tr:first td",a.tBodies[0]).each(function(){c.append($('