mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Pager: include settings parameter from ajaxError method & prevent js error. Fixes #997
This commit is contained in:
parent
c602ca7f01
commit
d1e9530bcf
@ -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 );
|
||||
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, exception );
|
||||
valid = wo.pager_ajaxError( c, xhr, settings, exception );
|
||||
if ( valid === false ) {
|
||||
return removeRow();
|
||||
} else {
|
||||
message = valid;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
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 !== 'undefined' ) {
|
||||
} else if ( typ === 'string' ) {
|
||||
// keep backward compatibility (external usage just passes a message string)
|
||||
message = xhr;
|
||||
}
|
||||
|
||||
if ( message === '' ) {
|
||||
} else {
|
||||
// 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) : $('<tr><td colspan="' + c.columns + '">' + message + '</td></tr>') )
|
||||
.click( function() {
|
||||
$( this ).remove();
|
||||
|
File diff suppressed because one or more lines are too long
2
dist/js/widgets/widget-pager.min.js
vendored
2
dist/js/widgets/widget-pager.min.js
vendored
File diff suppressed because one or more lines are too long
@ -69,6 +69,11 @@
|
||||
return url;
|
||||
},
|
||||
|
||||
// ajax error callback from $.tablesorter.showError function
|
||||
// ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
||||
// returning false will abort the error message
|
||||
ajaxError: null,
|
||||
|
||||
// add more ajax settings here
|
||||
// see http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
|
||||
ajaxObject: {
|
||||
|
@ -38,6 +38,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, settings, exception ){ return exception; };
|
||||
// returning false will abort the error message
|
||||
ajaxError: null,
|
||||
|
||||
// add more ajax settings here
|
||||
// see http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
|
||||
ajaxObject: { dataType: 'json' },
|
||||
|
@ -80,6 +80,11 @@
|
||||
return url;
|
||||
},
|
||||
|
||||
// ajax error callback from $.tablesorter.showError function
|
||||
// pager_ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
||||
// returning false will abort the error message
|
||||
pager_ajaxError: null,
|
||||
|
||||
// modify the $.ajax object to allow complete control over your ajax requests
|
||||
pager_ajaxObject: {
|
||||
dataType: 'json'
|
||||
|
@ -73,6 +73,11 @@
|
||||
// modify the url after all processing has been applied
|
||||
pager_customAjaxUrl: function(table, url) { return url; },
|
||||
|
||||
// ajax error callback from $.tablesorter.showError function
|
||||
// pager_ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
||||
// returning false will abort the error message
|
||||
pager_ajaxError: null,
|
||||
|
||||
// modify the $.ajax object to allow complete control over your ajax requests
|
||||
pager_ajaxObject: {
|
||||
dataType: 'json'
|
||||
|
@ -3832,9 +3832,14 @@ $('table').trigger('search', false);</pre></div>
|
||||
<td>Function</td>
|
||||
<td>null</td>
|
||||
<td>
|
||||
This callback allows you to customize the error message displayed in the <code>thead</code> (<span class="version">v2.23.0</span>).
|
||||
This callback allows you to customize the error message displayed in the <code>thead</code> (<span class="version">v2.23.0</span>; <span class="version updated">v2.23.1</span>).
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
In <span class="version updated">v2.23.1</span>
|
||||
<ul>
|
||||
<li>A <code>settings</code> parameter was added <em>before</em> the <code>exception</code> parameter to exactly match the parameters returned by the jQuery <a href="http://api.jquery.com/ajaxError/">.ajaxError()</a> method.</li>
|
||||
<li>This function is now always called, even if the <code>$.tablesorter.showError</code> function is called by an external function with only a string.</li>
|
||||
</ul>
|
||||
<span class="label label-info">Note</span> The pager widget equivalent option is within the <code>widgetOptions</code> and accessed via <code>widgetOptions.pager_ajaxError</code><br>
|
||||
<br>
|
||||
When there is an ajax error, the <a href="#function-showError"><code>$.tablesorter.showError</code></a> function is called. In <span class="version">v2.23.0</span>, that function now checks this callback to allow adding a custom error message.<br>
|
||||
@ -3844,7 +3849,7 @@ $('table').trigger('search', false);</pre></div>
|
||||
$("table")
|
||||
.tablesorter()
|
||||
.tablesorterPager({
|
||||
ajaxError: function( config, xhr, exception ) {
|
||||
ajaxError: function( config, xhr, settings, exception ) {
|
||||
// returning false will abort the error message
|
||||
// the code below is the default behavior when this callback is set to `null`
|
||||
return
|
||||
@ -6960,12 +6965,14 @@ $.tablesorter.isDigit( "(2,345.67)" );</pre>
|
||||
<td>This function allows adding/removing a row to the thead, to display any errors (<span class="version">v2.15</span>; <span class="version updated">v2.23.0</span>).
|
||||
<div class="collapsible">
|
||||
<p>This function is ONLY included within the <code>widget-pager.js</code> and <code>jquery.tablesorter.pager.js</code> files; in version 3+, I plan to add it as a selectable option in a build.</p>
|
||||
<p>In <span class="version updated">v2.23.1</span>, a <code>settings</code> parameter was included to make it match the parametered returned by the jQuery <a href="http://api.jquery.com/ajaxError/"><code>.ajaxError()</code> method</a>.</p>
|
||||
<p>In <span class="version updated">v2.23.0</span>, this function will accept <code>xhr</code> and <code>exception</code> parameters provided by ajax error messages. To maintain backward compatibility, if <code>xhr</code> is a string, it will be treated as previous <code>message</code> parameter and displayed in the error row without modification.</p>
|
||||
Use it as follows:
|
||||
<pre class="prettyprint lang-js">$.tablesorter.showError( table, xhr, exception );</pre>
|
||||
<pre class="prettyprint lang-js">$.tablesorter.showError( table, xhr, settings, exception );</pre>
|
||||
<ul>
|
||||
<li><code>table</code> - table DOM element (or jQuery object) of the table.</li>
|
||||
<li><code>xhr</code> - a plain string, string of an HTML row, or the XMLHttpRequest (XHR) object from ajax error message.</li>
|
||||
<li><code>settings</code> - a plain object containing the ajax settings, as returned by the ajaxError method.</li>
|
||||
<li><code>exception</code> - exception string passed from the ajax error message.</li>
|
||||
</ul>
|
||||
This function will add a table row to the thead, with a class name from either the pager plugin <code>cssErrorRow</code> option setting, or the pager widget <code>pager_css.errorRow</code> option (the default class name is <code>"tablesorter-errorRow"</code>; and styled within each theme css file).
|
||||
|
@ -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 );
|
||||
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, exception );
|
||||
valid = wo.pager_ajaxError( c, xhr, settings, exception );
|
||||
if ( valid === false ) {
|
||||
return removeRow();
|
||||
} else {
|
||||
message = valid;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
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 !== 'undefined' ) {
|
||||
} else if ( typ === 'string' ) {
|
||||
// keep backward compatibility (external usage just passes a message string)
|
||||
message = xhr;
|
||||
}
|
||||
|
||||
if ( message === '' ) {
|
||||
} else {
|
||||
// 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) : $('<tr><td colspan="' + c.columns + '">' + message + '</td></tr>') )
|
||||
.click( function() {
|
||||
$( this ).remove();
|
||||
|
Loading…
Reference in New Issue
Block a user