diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index 86da0919..073c4d86 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -26,7 +26,7 @@ customAjaxUrl: function(table, url) { return url; }, // ajax error callback from $.tablesorter.showError function - // ajaxError: function( config, xhr, exception ){ return exception; }; + // ajaxError: function( config, xhr, settings, exception ){ return exception; }; // returning false will abort the error message ajaxError: null, @@ -379,7 +379,7 @@ } }, - renderAjax = function(data, table, p, xhr, exception){ + renderAjax = function(data, table, p, xhr, settings, exception){ // process data if ( typeof p.ajaxProcessing === 'function' ) { // ajaxProcessing result: [ total, rows, headers ] @@ -395,9 +395,9 @@ if ( exception ) { if (c.debug) { - console.error('Pager: >> Ajax Error', xhr, exception); + console.error('Pager: >> Ajax Error', xhr, settings, exception); } - ts.showError( table, xhr, exception ); + ts.showError( table, xhr, settings, exception ); c.$tbodies.eq(0).children('tr').detach(); p.totalRows = 0; } else { @@ -522,7 +522,7 @@ ts.isProcessing(table, true); // show loading icon } $doc.bind('ajaxError' + namespace, function(e, xhr, settings, exception) { - renderAjax(null, table, p, xhr, exception); + renderAjax(null, table, p, xhr, settings, exception); $doc.unbind('ajaxError' + namespace); }); @@ -1067,12 +1067,14 @@ }() }); // see #486 - ts.showError = function( table, xhr, exception ) { + ts.showError = function( table, xhr, settings, exception ) { var $row, $table = $( table ), c = $table[0].config, wo = c && c.widgetOptions, - errorRow = c.pager && c.pager.cssErrorRow || wo.pager_css && wo.pager_css.errorRow || 'tablesorter-errorRow', + errorRow = c.pager && c.pager.cssErrorRow || + wo && wo.pager_css && wo.pager_css.errorRow || + 'tablesorter-errorRow', typ = typeof xhr, valid = true, message = '', @@ -1085,23 +1087,25 @@ return; } - if ( typ !== 'string' ) { - // ajaxError callback for plugin or widget - see #992 - if ( typeof c.pager.ajaxError === 'function' ) { - valid = c.pager.ajaxError( c, xhr, exception ); - if ( valid === false ) { - return removeRow(); - } else { - message = valid; - } - } else if ( typeof wo.pager_ajaxError === 'function' ) { - valid = wo.pager_ajaxError( c, xhr, exception ); - if ( valid === false ) { - return removeRow(); - } else { - message = valid; - } + // ajaxError callback for plugin or widget - see #992 + if ( typeof c.pager.ajaxError === 'function' ) { + valid = c.pager.ajaxError( c, xhr, settings, exception ); + if ( valid === false ) { + return removeRow(); } else { + message = valid; + } + } else if ( typeof wo.pager_ajaxError === 'function' ) { + valid = wo.pager_ajaxError( c, xhr, settings, exception ); + if ( valid === false ) { + return removeRow(); + } else { + message = valid; + } + } + + if ( message === '' ) { + if ( typ === 'object' ) { message = xhr.status === 0 ? 'Not connected, verify Network' : xhr.status === 404 ? 'Requested page not found [404]' : @@ -1110,18 +1114,16 @@ exception === 'timeout' ? 'Time out error' : exception === 'abort' ? 'Ajax Request aborted' : 'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']'; + } else if ( typ === 'string' ) { + // keep backward compatibility (external usage just passes a message string) + message = xhr; + } else { + // remove all error rows + return removeRow(); } - } else if ( typ !== 'undefined' ) { - // keep backward compatibility (external usage just passes a message string) - message = xhr; } - if ( message === '' ) { - // remove all error rows - return removeRow(); - } - - // allow message to include HTML (must include entire row!) + // allow message to include entire row HTML! $row = ( /tr\>/.test(message) ? $(message) : $('
thead
(v2.23.0).
+ This callback allows you to customize the error message displayed in the thead
(v2.23.0; v2.23.1).
settings
parameter was added before the exception
parameter to exactly match the parameters returned by the jQuery .ajaxError() method.$.tablesorter.showError
function is called by an external function with only a string.widgetOptions
and accessed via widgetOptions.pager_ajaxError
$.tablesorter.showError
function is called. In v2.23.0, that function now checks this callback to allow adding a custom error message.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.23.1, a settings
parameter was included to make it match the parametered returned by the jQuery .ajaxError()
method.
In v2.23.0, 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, xhr, exception );+
$.tablesorter.showError( table, xhr, settings, exception );
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.settings
- a plain object containing the ajax settings, as returned by the ajaxError method.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).
diff --git a/js/widgets/widget-pager.js b/js/widgets/widget-pager.js
index a5a8c1bb..e70fc620 100644
--- a/js/widgets/widget-pager.js
+++ b/js/widgets/widget-pager.js
@@ -63,7 +63,7 @@
pager_customAjaxUrl: function(table, url) { return url; },
// ajax error callback from $.tablesorter.showError function
- // pager_ajaxError: function( config, xhr, exception ){ return exception; };
+ // pager_ajaxError: function( config, xhr, settings, exception ){ return exception; };
// returning false will abort the error message
pager_ajaxError: null,
@@ -645,7 +645,7 @@
}
},
- renderAjax: function(data, table, c, xhr, exception){
+ renderAjax: function(data, table, c, xhr, settings, exception) {
var p = c.pager,
wo = c.widgetOptions;
// process data
@@ -662,9 +662,9 @@
if ( exception ) {
if (c.debug) {
- console.error('Pager: >> Ajax Error', xhr, exception);
+ console.error('Pager: >> Ajax Error', xhr, settings, exception);
}
- ts.showError( table, xhr, exception );
+ ts.showError( table, xhr, settings, exception );
c.$tbodies.eq(0).children('tr').detach();
p.totalRows = 0;
} else {
@@ -782,7 +782,7 @@
ts.isProcessing(table, true); // show loading icon
}
$doc.on('ajaxError' + namespace, function(e, xhr, settings, exception) {
- tsp.renderAjax(null, table, c, xhr, exception);
+ tsp.renderAjax(null, table, c, xhr, settings, exception);
$doc.off('ajaxError' + namespace);
});
counter = ++p.ajaxCounter;
@@ -1142,12 +1142,14 @@
};
// see #486
- ts.showError = function( table, xhr, exception ) {
+ ts.showError = function( table, xhr, settings, exception ) {
var $row,
$table = $( table ),
c = $table[0].config,
wo = c && c.widgetOptions,
- errorRow = c.pager && c.pager.cssErrorRow || wo.pager_css && wo.pager_css.errorRow || 'tablesorter-errorRow',
+ errorRow = c.pager && c.pager.cssErrorRow ||
+ wo && wo.pager_css && wo.pager_css.errorRow ||
+ 'tablesorter-errorRow',
typ = typeof xhr,
valid = true,
message = '',
@@ -1160,23 +1162,25 @@
return;
}
- if ( typ !== 'string' ) {
- // ajaxError callback for plugin or widget - see #992
- if ( typeof c.pager.ajaxError === 'function' ) {
- valid = c.pager.ajaxError( c, xhr, exception );
- if ( valid === false ) {
- return removeRow();
- } else {
- message = valid;
- }
- } else if ( typeof wo.pager_ajaxError === 'function' ) {
- valid = wo.pager_ajaxError( c, xhr, exception );
- if ( valid === false ) {
- return removeRow();
- } else {
- message = valid;
- }
+ // ajaxError callback for plugin or widget - see #992
+ if ( typeof c.pager.ajaxError === 'function' ) {
+ valid = c.pager.ajaxError( c, xhr, settings, exception );
+ if ( valid === false ) {
+ return removeRow();
} else {
+ message = valid;
+ }
+ } else if ( typeof wo.pager_ajaxError === 'function' ) {
+ valid = wo.pager_ajaxError( c, xhr, settings, exception );
+ if ( valid === false ) {
+ return removeRow();
+ } else {
+ message = valid;
+ }
+ }
+
+ if ( message === '' ) {
+ if ( typ === 'object' ) {
message =
xhr.status === 0 ? 'Not connected, verify Network' :
xhr.status === 404 ? 'Requested page not found [404]' :
@@ -1185,18 +1189,16 @@
exception === 'timeout' ? 'Time out error' :
exception === 'abort' ? 'Ajax Request aborted' :
'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']';
+ } else if ( typ === 'string' ) {
+ // keep backward compatibility (external usage just passes a message string)
+ message = xhr;
+ } else {
+ // remove all error rows
+ return removeRow();
}
- } else if ( typ !== 'undefined' ) {
- // keep backward compatibility (external usage just passes a message string)
- message = xhr;
}
- if ( message === '' ) {
- // remove all error rows
- return removeRow();
- }
-
- // allow message to include HTML (must include entire row!)
+ // allow message to include entire row HTML!
$row = ( /tr\>/.test(message) ? $(message) : $('