diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index bcf60856..43fa6c9e 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -25,6 +25,11 @@ // modify the url after all processing has been applied customAjaxUrl: function(table, url) { return url; }, + // ajax error callback from $.tablesorter.showError function + // ajaxError: function( config, xhr, exception ){ return exception; }; + // returning false will abort the error message + ajaxError: null, + // modify the $.ajax object to allow complete control over your ajax requests ajaxObject: { dataType: 'json' @@ -386,20 +391,13 @@ hl = $table.find('thead th').length; // Clean up any previous error. - ts.showError(table); + ts.showError( table ); if ( exception ) { if (c.debug) { console.error('Pager: >> Ajax Error', xhr, exception); } - ts.showError(table, - xhr.status === 0 ? 'Not connected, verify Network' : - xhr.status === 404 ? 'Requested page not found [404]' : - xhr.status === 500 ? 'Internal Server Error [500]' : - exception === 'parsererror' ? 'Requested JSON parse failed' : - exception === 'timeout' ? 'Time out error' : - exception === 'abort' ? 'Ajax Request aborted' : - 'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']' ); + ts.showError( table, xhr, exception ); c.$tbodies.eq(0).children('tr').detach(); p.totalRows = 0; } else { @@ -1069,31 +1067,73 @@ }() }); // see #486 - ts.showError = function(table, message) { - var index, $row, c, errorRow, + ts.showError = function( table, xhr, exception ) { + var $row, $table = $( table ), - len = $table.length; - for ( index = 0; index < len; index++ ) { - c = $table[ index ].config; - if ( c ) { - errorRow = c.pager && c.pager.cssErrorRow || c.widgetOptions.pager_css && c.widgetOptions.pager_css.errorRow || 'tablesorter-errorRow'; - if ( typeof message === 'undefined' ) { - c.$table.find('thead').find(c.selectorRemove).remove(); - } else { - $row = ( /tr\>/.test(message) ? $(message) : $('
thead
(v2.22.6).
+ $.tablesorter.showError
function is called. In v2.22.6, that function now checks this callback to allow adding a custom error message.$(function(){ + $("table") + .tablesorter() + .tablesorterPager({ + ajaxError: function( config, xhr, exception ) { + // returning false will abort the error message + // the code below is the default behavior when this callback is set to `null` + return + xhr.status === 0 ? 'Not connected, verify Network' : + xhr.status === 404 ? 'Requested page not found [404]' : + xhr.status === 500 ? 'Internal Server Error [500]' : + exception === 'parsererror' ? 'Requested JSON parse failed' : + exception === 'timeout' ? 'Time out error' : + exception === 'abort' ? 'Ajax Request aborted' : + 'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']' ); + } + }); +});
widget-pager.js
and jquery.tablesorter.pager.js
files; in version 3+, I plan to add it as a selectable option in a build.This function is ONLY included within the widget-pager.js
and jquery.tablesorter.pager.js
files; in version 3+, I plan to add it as a selectable option in a build.
In v2.22.6, this function will accept xhr
and exception
parameters provided by ajax error messages. To maintain backward compatibility, if xhr
is a string, it will be treated as previous message
parameter and displayed in the error row without modification.
$.tablesorter.showError( table, message );+
$.tablesorter.showError( table, xhr, exception );
table
- table DOM element (or jQuery object) of table (or tables).message
- a plain string, or string of an HTML row.table
- table DOM element (or jQuery object) of the table.xhr
- a plain string, string of an HTML row, or the XMLHttpRequest (XHR) object from ajax error message.exception
- exception string passed from the ajax error message.cssErrorRow
option setting, or the pager widget pager_css.errorRow
option (the default class name is "tablesorter-errorRow"
; and styled within each theme css file).cssErrorRow
option setting, or the pager widget pager_css.errorRow
option (the default class name is "tablesorter-errorRow"
; and styled within each theme css file).
+ When passing this function a message string (in the xhr
parameter), there are three possibilities:
"table refuses to cooperate"
"<strong>table refuses to cooperate</strong>"
'<tr><td colspan="' + table.config.columns + '">yeah, instead of showing your data... I am taking a nap</td></tr>'
(the table.config.columns
variable contains the number of table columns; use as needed)$.tablesorter.showError( table );
to remove all error rows from the table thead.table
parameter no longer accepts multiple tables.xhr
parameter is not a string, then the pager ajaxError
callback is called to allow modification of the displayed message.