From c967fac0999b51913c21d7b56181d0819a56f945 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Fri, 16 Mar 2012 23:13:22 -0500 Subject: [PATCH] modified ajaxProcessing in pager plugin --- README.markdown | 40 +++- addons/pager/jquery.tablesorter.pager.js | 156 +++++++++------- addons/pager/jquery.tablesorter.pager.min.js | 4 +- changelog.txt | 39 ++++ docs/assets/City0.json | 10 +- docs/assets/City1.json | 28 +-- docs/assets/City2.json | 22 ++- docs/assets/City3.json | 12 +- docs/example-pager-ajax.html | 185 ++++++++++++------- package.json | 2 +- 10 files changed, 334 insertions(+), 164 deletions(-) diff --git a/README.markdown b/README.markdown index 8d9af019..9b694c7d 100644 --- a/README.markdown +++ b/README.markdown @@ -27,13 +27,51 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs ###Licensing * Copyright (c) 2007 Christian Bach -* Main Examples and docs at: [http://tablesorter.com](http://tablesorter.com) +* Original examples and docs at: [http://tablesorter.com](http://tablesorter.com) * Dual licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) and [GPL](http://www.gnu.org/licenses/gpl.html) licenses: ###Change Log View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt). +#### Version 2.1.3 (3/12/2012) + +* Added `usNumberFormat` option. + * Set to `true` for U.S. number format: `1,234,567.89` + * Set to `false` for German `1.234.567,89` or French `1 234 567,89` formats.' + * Fix for [issue #34](https://github.com/Mottie/tablesorter/issues/34) and [issue # 31](https://github.com/Mottie/tablesorter/issues/31#issuecomment-4236945). +* Changed pager plugin ajax functions & demo + * The `ajaxProcessing` function now must now return two or three pieces of information: [ total, rows, headers ] + * `total` is the total number of rows in the database. + * `rows` is an array of table rows with an array of table cells in each row. + * `headers` is an array of header cell text (optional). + + ```javascript + // process ajax so that the following information is returned: + // [ total_rows (number), rows (array of arrays), headers (array; optional) ] + // example: + [ + // total # rows contained in the database + 100, + // row data: array of arrays; each internal array has the table data + [ + [ "row1cell1", "row1cell2", ... "row1cellN" ], + [ "row2cell1", "row2cell2", ... "row2cellN" ], + ... + [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] + ], + // header text (optional) + [ "Header1", "Header2", ... "HeaderN" ] + ] + ``` + + * Modified pager plugin ajax demo to hopefully make the data processing a bit more clear by changing `data` inside of the City#.json files to `rows`. + * The demo json data should now render the unicode characters properly. Switched the files to the proper utf-8 encoding. + * When no data is returned, the table will now: + * Insert a row into the header showing the ajax error. If a row is inserted into the tbody, clicking on the header would cause a parser error. + * Disable the pager so the pager counter won't show zero total rows. + * Fix for issue dicussed within [issue #31](https://github.com/Mottie/tablesorter/issues/31#issuecomment-4390379). + #### Version 2.1.2 (3/11/2012) * Added `table` and `cellIndex` variables to the `textExtraction` function to allow using a more general function for text extraction. diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index 3971cd3c..509974e7 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -1,6 +1,6 @@ /* * tablesorter pager plugin - * updated 3/8/2012 + * updated 3/16/2012 */ (function($) { @@ -14,8 +14,20 @@ // where {page} is replaced by the page number and {size} is replaced by the number of records to show ajaxUrl: null, - // process ajax so that the data object is returned along with the total number of rows - ajaxProcessing: function(ajax){ return [ [{ "key" : "value" }], 100 ]; }, + // process ajax so that the following information is returned: + // [ total_rows (number), rows (array of arrays), headers (array; optional) ] + // example: + // [ + // 100, // total rows + // [ + // [ "row1cell1", "row1cell2", ... "row1cellN" ], + // [ "row2cell1", "row2cell2", ... "row2cellN" ], + // ... + // [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] + // ], + // [ "header1", "header2", ... "headerN" ] // optional + // ] + ajaxProcessing: function(ajax){ return [ 0, [], null ]; }, // output default: '{page}/{totalPages}' output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}' @@ -68,21 +80,23 @@ }, updatePageDisplay = function(table, c) { - c.startRow = c.size * (c.page) + 1; - c.endRow = Math.min(c.totalRows, c.size * (c.page+1)); - var out = $(c.cssPageDisplay, c.container), - // form the output string - s = c.output.replace(/\{(page|totalPages|startRow|endRow|totalRows)\}/gi, function(m){ - return { - '{page}' : c.page + 1, - '{totalPages}' : c.totalPages, - '{startRow}' : c.startRow, - '{endRow}' : c.endRow, - '{totalRows}' : c.totalRows - }[m]; - }); - if (out[0]) { - out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s); + if (c.totalPages > 0) { + c.startRow = c.size * (c.page) + 1; + c.endRow = Math.min(c.totalRows, c.size * (c.page+1)); + var out = $(c.cssPageDisplay, c.container), + // form the output string + s = c.output.replace(/\{(page|totalPages|startRow|endRow|totalRows)\}/gi, function(m){ + return { + '{page}' : c.page + 1, + '{totalPages}' : c.totalPages, + '{startRow}' : c.startRow, + '{endRow}' : c.endRow, + '{totalRows}' : c.totalRows + }[m]; + }); + if (out[0]) { + out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s); + } } pagerArrows(c); $(table).trigger('pagerComplete', c); @@ -134,59 +148,77 @@ } }, + renderAjax = function(data, table, c, exception){ + // process data + if (typeof(c.ajaxProcessing) === "function") { + // ajaxProcessing result: [ total, rows, headers ] + var i, j, k, hsh, $sh, $t = $(table), $b = $(table.tBodies[0]), + hl = $t.find('thead th').length, tf = '', tds = '', + err = '' + + (exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '', + result = c.ajaxProcessing(data) || [ 0, [] ], + d = result[1] || [], l = d.length, th = result[2]; + if (l > 0) { + for ( i=0; i < l; i++ ) { + tds += ''; + for (j=0; j < d[i].length; j++) { + // build tbody cells + tds += '' + d[i][j] + ''; + } + tds += ''; + } + } + // only add new header text if the length matches + if (th && th.length === hl) { + hsh = $t.hasClass('hasStickyHeaders'); + $sh = $t.find('.' + ((c.widgetOptions && c.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader')); + $t.find('thead tr.tablesorter-header th').each(function(j){ + var $t = $(this), + // add new test within the first span it finds, or just in the header + tar = ($t.find('span').length) ? $t.find('span:first') : $t; + tar.html(th[j]); + // update sticky headers + if (hsh && $sh.length){ + tar = $sh.find('th').eq(j); + tar = (tar.find('span').length) ? tar.find('span:first') : tar; + tar.html(th[j]); + } + tf += '' + th[j] + ''; + }); + $t.find('tfoot').html('' + tf + ''); + } + if (exception) { + // add error row to thead instead of tbody, or clicking on the header will result in a parser error + $t.find('thead').append(err); + } else { + $b.html(tds); // add tbody + } + c.temp.remove(); // remove loading icon + $t.trigger('update'); + c.totalRows = result[0] || 0; + c.totalPages = Math.ceil(c.totalRows / c.size); + updatePageDisplay(table, c); + fixHeight(table, c); + $t.trigger('pagerChange', c); + } + }, + getAjax = function(table, c){ - var i, $load, $t = $(table), $b = $(table.tBodies[0]), + var $t = $(table), url = c.ajaxUrl.replace(/\{page\}/g, c.page).replace(/\{size\}/g, c.size); if (url !== '') { // loading icon - $load = $('
', { + c.temp = $('
', { id : 'tablesorterPagerLoading', width : $t.outerWidth(true), height: $t.outerHeight(true) }); - $t.before($load); + $t.before(c.temp); + $(document).ajaxError(function(e, xhr, settings, exception) { + renderAjax(null, table, c, exception); + }); $.getJSON(url, function(data) { - // process data - if (typeof(c.ajaxProcessing) === "function") { - var result = c.ajaxProcessing(data), d = result[0], l = d.length, - i, k, th = [], tds = '', tf = '', hsh = $(table).addClass('hasStickyHeaders'), - sh = '.' + ((table.config.widgetOptions && table.config.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader'), - $sh = $t.find(sh); - for ( i=0; i < l; i++ ) { - tds += ''; - for (k in d[i]) { - if (typeof(k) === "string") { - // get new header text - if ( i === 0 ) { th.push(k); } - // build tbody cells - tds += '' + d[i][k] + ''; - } - } - tds += ''; - } - $t.find('thead tr.tablesorter-header th').each(function(j){ - var $t = $(this), - // add new test within the first span it finds, or just in the header - tar = ($t.find('span').length) ? $t.find('span:first') : $t; - tar.html(th[j]); - // update sticky headers - if (hsh && $sh.length){ - tar = $sh.find('th').eq(j); - tar = (tar.find('span').length) ? tar.find('span:first') : tar; - tar.html(th[j]); - } - tf += '' + th[j] + ''; - }); - $t.find('tfoot').html('' + tf + ''); - $b.html(tds); // add tbody - $load.remove(); // remove loading icon - $t.trigger('update'); - c.totalRows = result[1]; - c.totalPages = Math.ceil(c.totalRows / c.size); - updatePageDisplay(table, c); - fixHeight(table, c); - $t.trigger('pagerChange', c); - } + renderAjax(data, table, c); }); } }, diff --git a/addons/pager/jquery.tablesorter.pager.min.js b/addons/pager/jquery.tablesorter.pager.min.js index 7cf75d89..4484168d 100644 --- a/addons/pager/jquery.tablesorter.pager.min.js +++ b/addons/pager/jquery.tablesorter.pager.min.js @@ -1,3 +1,3 @@ -/* tablesorter pager plugin minified - updated 3/8/2012 */ +/* tablesorter pager plugin minified - updated 3/16/2012 */ -(function(d){d.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(){return[[{key:"value"}],100]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,fixedHeight:!1,removeRows:!0,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0};var h=this,i=function(c,b){var a=c.cssDisabled,e=!!b;c.updateArrows&& (c.container[c.totalRows')},l=function(c,b){var a, e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies[0]),g=e.length,f=b.page*b.size,n=f+b.size;n>g&&(n=g);for(a=0;a=f&&a", {id:"tablesorterPagerLoading",width:e.outerWidth(!0),height:e.outerHeight(!0)}),e.before(a),d.getJSON(f,function(f){if("function"===typeof b.ajaxProcessing){var f=b.ajaxProcessing(f),r=f[0],j=r.length,m,p,q=[],k="",h="",i=d(c).addClass("hasStickyHeaders"),l=e.find("."+(c.config.widgetOptions&&c.config.widgetOptions.stickyHeaders||"tablesorter-stickyheader"));for(m=0;m";for(p in r[m])"string"===typeof p&&(0===m&&q.push(p),k+=""+r[m][p]+"");k+=""}e.find("thead tr.tablesorter-header th").each(function(b){var a= d(this),a=a.find("span").length?a.find("span:first"):a;a.html(q[b]);i&&l.length&&(a=l.find("th").eq(b),a=a.find("span").length?a.find("span:first"):a,a.html(q[b]));h+=""+q[b]+""});e.find("tfoot").html(""+h+"");g.html(k);a.remove();e.trigger("update");b.totalRows=f[1];b.totalPages=Math.ceil(b.totalRows/b.size);t(c,b);o(c,b);e.trigger("pagerChange",b)}}))},s=function(c,b,a){var e,g,f,n=d(c.tBodies[0]),h=b.length;e=a.page*a.size;var i=e+a.size;if(!(1>h)){d(c).trigger("pagerChange", a);if(a.removeRows){i>b.length&&(i=b.length);for(d(c.tBodies[0]).empty();e=a.totalPages&&(a.page=a.totalPages-1,j(c,a));t(c,a);a.isDisabled||o(c,a)}},w=function(c,b){b.ajax?i(b,!0):(b.isDisabled=!0,d.data(c,"pagerLastPage",b.page),d.data(c,"pagerLastSize",b.size),b.page=0,b.size=b.totalRows,b.totalPages=1,d("tr.pagerSavedHeightSpacer",c.tBodies[0]).remove(),s(c,c.config.rowsCopy,b));d(b.cssPageSize, b.container).addClass(b.cssDisabled)[0].disabled=!0},j=function(c,b){if(!b.isDisabled){if(0>b.page||b.page>b.totalPages-1)b.page=0;d.data(c,"pagerLastPage",b.page);b.ajax?v(c,b):s(c,c.config.rowsCopy,b)}},x=function(c,b,a){a.size=b;d.data(c,"pagerLastPage",a.page);d.data(c,"pagerLastSize",a.size);a.totalPages=Math.ceil(a.totalRows/a.size);j(c,a)},y=function(c,b,a){var e=d(b.cssPageSize,b.container).removeClass(b.cssDisabled).removeAttr("disabled");b.isDisabled=!1;b.page=d.data(c,"pagerLastPage")|| 0;b.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10);b.totalPages=Math.ceil(b.totalRows/b.size);a&&(d("table").trigger("update"),x(c,b.size,b),u(c,b),o(c,b))};h.appender=function(c,b){var a=c.config.pager;a.ajax||(c.config.rowsCopy=b,a.totalRows=b.length,a.size=d.data(c,"pagerLastSize")||a.size,a.totalPages=Math.ceil(a.totalRows/a.size),s(c,b,a))};h.construct=function(c){return this.each(function(){var b=this.config,a=b.pager=d.extend({},d.tablesorterPager.defaults,c),e=this,g=d(e),f=d(a.container).show(); b.appender=h.appender;y(e,a,!1);"string"===typeof a.ajaxUrl?(a.ajax=!0,v(e,a)):(a.ajax=!1,d(this).trigger("appendCache"),u(e,a));d(a.cssFirst,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page=0;j(e,a)}return false});d(a.cssNext,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page++;if(a.page>=a.totalPages-1)a.page=a.totalPages-1;j(e,a)}return false});d(a.cssPrev,f).unbind("click.pager").bind("click.pager", function(){if(!d(this).hasClass(a.cssDisabled)){a.page--;if(a.page<=0)a.page=0;j(e,a)}return false});d(a.cssLast,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page=a.totalPages-1;j(e,a)}return false});d(a.cssPageSize,f).unbind("change.pager").bind("change.pager",function(){d(a.cssPageSize,f).val(d(this).val());if(!d(this).hasClass(a.cssDisabled)){x(e,parseInt(d(this).val(),10),a);var b=d(e.tBodies[0]);b.find("tr.pagerSavedHeightSpacer").remove();d.data(e, "pagerSavedHeight",b.height());o(e,a);d.data(e,"pagerLastSize",a.size)}return false});g.unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){w(e,a)}).bind("enable.pager",function(){y(e,a,true)}).bind("destroy.pager",function(){w(e,a);a.container.hide();e.config.appender=null;d(e).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery); +(function(d){d.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,fixedHeight:!1,removeRows:!0,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0};var n=this,i=function(c,b){var a=c.cssDisabled,e=!!b;c.updateArrows&&(c.container[c.totalRows< c.size?"addClass":"removeClass"](a),d(c.cssFirst+","+c.cssPrev,c.container)[e||0===c.page?"addClass":"removeClass"](a),d(c.cssNext+","+c.cssLast,c.container)[e||c.page===c.totalPages-1?"addClass":"removeClass"](a))},t=function(c,b){if(0')},o=function(c,b){var a, e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies[0]),g=e.length,f=b.page*b.size,j=f+b.size;j>g&&(j=g);for(a=0;a=f&&a'+(e?e.message+" ("+e.name+")":"No rows found")+"",m=a.ajaxProcessing(c)||[0,[]],s=m[1]||[],p=s.length,q=m[2];if(0";for(g=0;g"+s[c][g]+"";l+=""}q&&q.length===n&&(f=h.hasClass("hasStickyHeaders"),j=h.find("."+(a.widgetOptions&&a.widgetOptions.stickyHeaders||"tablesorter-stickyheader")),h.find("thead tr.tablesorter-header th").each(function(a){var b=d(this), b=b.find("span").length?b.find("span:first"):b;b.html(q[a]);f&&j.length&&(b=j.find("th").eq(a),b=b.find("span").length?b.find("span:first"):b,b.html(q[a]));i+=""+q[a]+""}),h.find("tfoot").html(""+i+""));e?h.find("thead").append(o):k.html(l);a.temp.remove();h.trigger("update");a.totalRows=m[0]||0;a.totalPages=Math.ceil(a.totalRows/a.size);t(b,a);r(b,a);h.trigger("pagerChange",a)}},v=function(c,b){var a=d(c),e=b.ajaxUrl.replace(/\{page\}/g,b.page).replace(/\{size\}/g,b.size);""!== e&&(b.temp=d("
",{id:"tablesorterPagerLoading",width:a.outerWidth(!0),height:a.outerHeight(!0)}),a.before(b.temp),d(document).ajaxError(function(a,d,e,h){u(null,c,b,h)}),d.getJSON(e,function(a){u(a,c,b)}))},m=function(c,b,a){var e,g,f,j=d(c.tBodies[0]),h=b.length;e=a.page*a.size;var i=e+a.size;if(!(1>h)){d(c).trigger("pagerChange",a);if(a.removeRows){i>b.length&&(i=b.length);for(d(c.tBodies[0]).empty();e=a.totalPages&&(a.page=a.totalPages-1,k(c,a));t(c,a);a.isDisabled||r(c,a)}},w=function(c,b){b.ajax?i(b,!0):(b.isDisabled=!0,d.data(c,"pagerLastPage",b.page),d.data(c,"pagerLastSize",b.size),b.page=0,b.size=b.totalRows,b.totalPages=1,d("tr.pagerSavedHeightSpacer",c.tBodies[0]).remove(),m(c,c.config.rowsCopy,b));d(b.cssPageSize,b.container).addClass(b.cssDisabled)[0].disabled=!0},k=function(c,b){if(!b.isDisabled){if(0>b.page||b.page>b.totalPages-1)b.page=0;d.data(c,"pagerLastPage",b.page);b.ajax? v(c,b):m(c,c.config.rowsCopy,b)}},x=function(c,b,a){a.size=b;d.data(c,"pagerLastPage",a.page);d.data(c,"pagerLastSize",a.size);a.totalPages=Math.ceil(a.totalRows/a.size);k(c,a)},y=function(c,b,a){var e=d(b.cssPageSize,b.container).removeClass(b.cssDisabled).removeAttr("disabled");b.isDisabled=!1;b.page=d.data(c,"pagerLastPage")||0;b.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10);b.totalPages=Math.ceil(b.totalRows/b.size);a&&(d("table").trigger("update"),x(c,b.size,b),p(c,b),r(c,b))};n.appender= function(c,b){var a=c.config.pager;a.ajax||(c.config.rowsCopy=b,a.totalRows=b.length,a.size=d.data(c,"pagerLastSize")||a.size,a.totalPages=Math.ceil(a.totalRows/a.size),m(c,b,a))};n.construct=function(c){return this.each(function(){var b=this.config,a=b.pager=d.extend({},d.tablesorterPager.defaults,c),e=this,g=d(e),f=d(a.container).show();b.appender=n.appender;y(e,a,!1);"string"===typeof a.ajaxUrl?(a.ajax=!0,v(e,a)):(a.ajax=!1,d(this).trigger("appendCache"),p(e,a));d(a.cssFirst,f).unbind("click.pager").bind("click.pager", function(){if(!d(this).hasClass(a.cssDisabled)){a.page=0;k(e,a)}return false});d(a.cssNext,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page++;if(a.page>=a.totalPages-1)a.page=a.totalPages-1;k(e,a)}return false});d(a.cssPrev,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page--;if(a.page<=0)a.page=0;k(e,a)}return false});d(a.cssLast,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page= a.totalPages-1;k(e,a)}return false});d(a.cssPageSize,f).unbind("change.pager").bind("change.pager",function(){d(a.cssPageSize,f).val(d(this).val());if(!d(this).hasClass(a.cssDisabled)){x(e,parseInt(d(this).val(),10),a);var b=d(e.tBodies[0]);b.find("tr.pagerSavedHeightSpacer").remove();d.data(e,"pagerSavedHeight",b.height());r(e,a);d.data(e,"pagerLastSize",a.size)}return false});g.unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){w(e,a)}).bind("enable.pager",function(){y(e, a,true)}).bind("destroy.pager",function(){w(e,a);a.container.hide();e.config.appender=null;d(e).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery); diff --git a/changelog.txt b/changelog.txt index 736cbdd2..1964aff6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,44 @@ TableSorter Change Log +Version 2.1.3 (3/12/2012) +============================ + +* Added `usNumberFormat` option. + * Set to `true` for U.S. number format: `1,234,567.89` + * Set to `false` for German `1.234.567,89` or French `1 234 567,89` formats.' + * Fix for [issue #34](https://github.com/Mottie/tablesorter/issues/34) and [issue # 31](https://github.com/Mottie/tablesorter/issues/31#issuecomment-4236945). +* Changed pager plugin ajax functions & demo + * The `ajaxProcessing` function now must now return two or three pieces of information: [ total, rows, headers ] + * `total` is the total number of rows in the database. + * `rows` is an array of table rows with an array of table cells in each row. + * `headers` is an array of header cell text (optional). + + ```javascript + // process ajax so that the following information is returned: + // [ total_rows (number), rows (array of arrays), headers (array; optional) ] + // example: + [ + // total # rows contained in the database + 100, + // row data: array of arrays; each internal array has the table data + [ + [ "row1cell1", "row1cell2", ... "row1cellN" ], + [ "row2cell1", "row2cell2", ... "row2cellN" ], + ... + [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] + ], + // header text (optional) + [ "Header1", "Header2", ... "HeaderN" ] + ] + ``` + + * Modified pager plugin ajax demo to hopefully make the data processing a bit more clear by changing `data` inside of the City#.json files to `rows`. + * The demo json data should now render the unicode characters properly. Switched the files to the proper utf-8 encoding. + * When no data is returned, the table will now: + * Insert a row into the header showing the ajax error. If a row is inserted into the tbody, clicking on the header would cause a parser error. + * Disable the pager so the pager counter won't show zero total rows. + * Fix for issue dicussed within [issue #31](https://github.com/Mottie/tablesorter/issues/31#issuecomment-4390379). + Version 2.1.2 (3/11/2012) ============================ diff --git a/docs/assets/City0.json b/docs/assets/City0.json index e62ef11f..24697901 100644 --- a/docs/assets/City0.json +++ b/docs/assets/City0.json @@ -1,7 +1,11 @@ -{ + { "total_rows": "80", - "data" : [{ + "cols" : [ + "ID", "Name", "Country Code", "District", "Population" + ], + + "rows" : [{ "ID": 1, "Name": "Kabul", "CountryCode": "AFG", @@ -117,7 +121,7 @@ "Population": 135621 }, { "ID": 20, - "Name": "´s-Hertogenbosch", + "Name": "´s-Hertogenbosch", "CountryCode": "NLD", "District": "Noord-Brabant", "Population": 129170 diff --git a/docs/assets/City1.json b/docs/assets/City1.json index 9e3773fa..f1a27dfb 100644 --- a/docs/assets/City1.json +++ b/docs/assets/City1.json @@ -1,7 +1,11 @@ { "total_rows": "80", - "data" : [{ + "cols" : [ + "ID", "Name", "Country Code", "District", "Population" + ], + + "rows" : [{ "ID": 26, "Name": "Zoetermeer", "CountryCode": "NLD", @@ -47,7 +51,7 @@ "ID": 33, "Name": "Willemstad", "CountryCode": "ANT", - "District": "Curaçao", + "District": "Curaçao", "Population": 2345 }, { "ID": 34, @@ -87,15 +91,15 @@ "Population": 183377 }, { "ID": 40, - "Name": "Sétif", + "Name": "Sétif", "CountryCode": "DZA", - "District": "Sétif", + "District": "Sétif", "Population": 179055 }, { "ID": 41, - "Name": "Sidi Bel Abbès", + "Name": "Sidi Bel Abbès", "CountryCode": "DZA", - "District": "Sidi Bel Abbès", + "District": "Sidi Bel Abbès", "Population": 153106 }, { "ID": 42, @@ -117,9 +121,9 @@ "Population": 127284 }, { "ID": 45, - "Name": "Béjaïa", + "Name": "Béjaïa", "CountryCode": "DZA", - "District": "Béjaïa", + "District": "Béjaïa", "Population": 117162 }, { "ID": 46, @@ -129,9 +133,9 @@ "Population": 115212 }, { "ID": 47, - "Name": "Tébessa", + "Name": "Tébessa", "CountryCode": "DZA", - "District": "Tébessa", + "District": "Tébessa", "Population": 112007 }, { "ID": 48, @@ -141,9 +145,9 @@ "Population": 110242 }, { "ID": 49, - "Name": "Béchar", + "Name": "Béchar", "CountryCode": "DZA", - "District": "Béchar", + "District": "Béchar", "Population": 107311 }, { "ID": 50, diff --git a/docs/assets/City2.json b/docs/assets/City2.json index 011cb5f9..588c6df3 100644 --- a/docs/assets/City2.json +++ b/docs/assets/City2.json @@ -1,7 +1,11 @@ { "total_rows": "80", - "data" : [{ + "cols" : [ + "ID", "Name", "Country Code", "District", "Population" + ], + + "rows" : [{ "ID": 51, "Name": "Ech-Chleff (el-Asnam)", "CountryCode": "DZA", @@ -9,9 +13,9 @@ "Population": 96794 }, { "ID": 52, - "Name": "Ghardaïa", + "Name": "Ghardaïa", "CountryCode": "DZA", - "District": "Ghardaïa", + "District": "Ghardaïa", "Population": 89415 }, { "ID": 53, @@ -65,17 +69,17 @@ "ID": 61, "Name": "South Hill", "CountryCode": "AIA", - "District": "–", + "District": "–", "Population": 961 }, { "ID": 62, "Name": "The Valley", "CountryCode": "AIA", - "District": "–", + "District": "–", "Population": 595 }, { "ID": 63, - "Name": "Saint John´s", + "Name": "Saint John´s", "CountryCode": "ATG", "District": "St John", "Population": 24000 @@ -123,15 +127,15 @@ "Population": 1266461 }, { "ID": 71, - "Name": "Córdoba", + "Name": "Córdoba", "CountryCode": "ARG", - "District": "Córdoba", + "District": "Córdoba", "Population": 1157507 }, { "ID": 72, "Name": "Rosario", "CountryCode": "ARG", - "District": "Santa Fé", + "District": "Santa Fé", "Population": 907718 }, { "ID": 73, diff --git a/docs/assets/City3.json b/docs/assets/City3.json index c2918a64..f7239b3e 100644 --- a/docs/assets/City3.json +++ b/docs/assets/City3.json @@ -1,7 +1,11 @@ { "total_rows": "80", - "data" : [{ + "cols" : [ + "ID", "Name", "Country Code", "District", "Population" + ], + + "rows" : [{ "ID": 76, "Name": "La Plata", "CountryCode": "ARG", @@ -15,13 +19,13 @@ "Population": 512880 }, { "ID": 78, - "Name": "San Miguel de Tucumán", + "Name": "San Miguel de Tucumán", "CountryCode": "ARG", - "District": "Tucumán", + "District": "Tucumán", "Population": 470809 }, { "ID": 79, - "Name": "Lanús", + "Name": "Lanús", "CountryCode": "ARG", "District": "Buenos Aires", "Population": 469735 diff --git a/docs/example-pager-ajax.html b/docs/example-pager-ajax.html index 6e1ff314..75a239fd 100644 --- a/docs/example-pager-ajax.html +++ b/docs/example-pager-ajax.html @@ -17,47 +17,12 @@ - + - + +