mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Add showError function. Fixes #486
This commit is contained in:
parent
b1aa1b3879
commit
cb40882acc
@ -247,26 +247,21 @@
|
||||
result = p.ajaxProcessing(data, table) || [ 0, [] ],
|
||||
hl = $t.find('thead th').length;
|
||||
|
||||
$t.find('thead tr.' + p.cssErrorRow).remove(); // Clean up any previous error.
|
||||
// Clean up any previous error.
|
||||
ts.showError(table);
|
||||
|
||||
if ( exception ) {
|
||||
if (c.debug) {
|
||||
ts.log('Ajax Error', xhr, exception);
|
||||
}
|
||||
$err = $('<tr class="' + p.cssErrorRow + '" role="alert" aria-live="assertive">' +
|
||||
'<td style="text-align:center;" colspan="' + hl + '">' + (
|
||||
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 + ']' ) + '</td></tr>')
|
||||
.click(function(){
|
||||
$(this).remove();
|
||||
})
|
||||
// add error row to thead instead of tbody, or clicking on the header will result in a parser error
|
||||
.appendTo( $t.find('thead:first') );
|
||||
'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']' );
|
||||
c.$tbodies.eq(0).empty();
|
||||
} else {
|
||||
// process ajax object
|
||||
@ -757,8 +752,34 @@
|
||||
});
|
||||
};
|
||||
|
||||
}()
|
||||
});
|
||||
}() });
|
||||
|
||||
// see #486
|
||||
ts.showError = function(table, message){
|
||||
$(table).each(function(){
|
||||
var $row,
|
||||
c = this.config,
|
||||
errorRow = c.pager && c.pager.cssErrorRow || c.widgetOptions.pager_css && c.widgetOptions.pager_css.errorRow || 'tablesorter-errorRow';
|
||||
if (c) {
|
||||
if (typeof message === 'undefined') {
|
||||
c.$table.find('thead').find(c.selectorRemove).remove();
|
||||
} else {
|
||||
$row = ( /tr\>/.test(message) ? $(message) : $('<tr><td colspan="' + c.columns + '">' + message + '</td></tr>') )
|
||||
.click(function(){
|
||||
$(this).remove();
|
||||
})
|
||||
// add error row to thead instead of tbody, or clicking on the header will result in a parser error
|
||||
.appendTo( c.$table.find('thead:first') )
|
||||
.addClass( errorRow + ' ' + c.selectorRemove.replace(/^[.#]/, '') )
|
||||
.attr({
|
||||
role : 'alert',
|
||||
'aria-live' : 'assertive'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// extend plugin scope
|
||||
$.fn.extend({
|
||||
tablesorterPager: $.tablesorterPager.construct
|
||||
|
@ -176,6 +176,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -211,6 +211,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -133,6 +133,7 @@
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -134,6 +134,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -177,6 +177,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -202,6 +202,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -235,6 +235,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -191,6 +191,7 @@ caption {
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -144,6 +144,7 @@
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: #e6bf99;
|
||||
}
|
||||
|
@ -320,6 +320,7 @@
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter-errorRow td {
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
background-color: @errorBackground;
|
||||
}
|
||||
|
@ -2085,8 +2085,6 @@ $(function(){
|
||||
<td><a href="example-widget-filter-custom.html">Example</a></td>
|
||||
</tr>
|
||||
|
||||
: true, // hide filter row when table is empty
|
||||
|
||||
<tr id="widget-filter-hideempty">
|
||||
<td><a href="#" class="permalink">filter_hideEmpty</a></td>
|
||||
<td>Boolean</td>
|
||||
@ -4765,6 +4763,30 @@ $.tablesorter.isDigit( "(2,345.67)" );</pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="function-showError">
|
||||
<td><a href="#" class="permalink">showError</a></td>
|
||||
<td>This function allows adding/removing a row to the thead, to display any errors <span class="version">v2.15</span>
|
||||
<div class="collapsible"><br>
|
||||
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.<br>
|
||||
<br>
|
||||
Use it as follows:
|
||||
<pre class="prettyprint lang-js">$.tablesorter.showError( table, message );</pre>
|
||||
<ul>
|
||||
<li><code>table</code> - table DOM element (or jQuery object) of table (or tables).</li>
|
||||
<li><code>message</code> - a plain string, or string of an HTML row.</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 `"tablesorter-errorRow"`; and styled within each theme css file).<br>
|
||||
<br>
|
||||
When passing this function a message, there are three possibilities:
|
||||
<ol>
|
||||
<li>Plain string - <code>"table refuses to cooperate"</code></li>
|
||||
<li>HTML row string - <code>'<tr><td colspan="' + table.config.columns + '">yeah, instead of showing your data... I am taking a nap</td></tr>'</code> (the <a href="#variable-columns"><code>table.config.columns</code> variable</a> contains the number of table columns; use as needed)</li>
|
||||
<li>undefined - completely leave out a message parameter <code>$.tablesorter.showError( table );</code> to remove all error rows from the table thead.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
|
||||
<!-- non-sorting tbody -->
|
||||
|
@ -440,20 +440,14 @@ tsp = ts.pager = {
|
||||
result = wo.pager_ajaxProcessing(data, table) || [ 0, [] ],
|
||||
hl = $t.find('thead th').length;
|
||||
|
||||
$t.find('thead tr.' + wo.pager_css.errorRow).remove(); // Clean up any previous error.
|
||||
// Clean up any previous error.
|
||||
ts.showError(table);
|
||||
|
||||
if ( exception ) {
|
||||
if (c.debug) {
|
||||
ts.log('Ajax Error', xhr, exception);
|
||||
}
|
||||
$err = $('<tr class="' + wo.pager_css.errorRow + '" role="alert" aria-live="assertive">' +
|
||||
'<td style="text-align:center;" colspan="' +
|
||||
hl + '">' + exception.message + ' (' + xhr.status + ')</td></tr>')
|
||||
.click(function(){
|
||||
$(this).remove();
|
||||
})
|
||||
// add error row to thead instead of tbody, or clicking on the header will result in a parser error
|
||||
.appendTo( $t.find('thead:first') );
|
||||
ts.showError(table, exception.message + ' (' + xhr.status + ')');
|
||||
c.$tbodies.eq(0).empty();
|
||||
} else {
|
||||
// process ajax object
|
||||
@ -812,4 +806,30 @@ tsp = ts.pager = {
|
||||
|
||||
};
|
||||
|
||||
// see #486
|
||||
ts.showError = function(table, message){
|
||||
$(table).each(function(){
|
||||
var $row,
|
||||
c = this.config,
|
||||
errorRow = c.pager && c.pager.cssErrorRow || c.widgetOptions.pager_css && c.widgetOptions.pager_css.errorRow || 'tablesorter-errorRow';
|
||||
if (c) {
|
||||
if (typeof message === 'undefined') {
|
||||
c.$table.find('thead').find(c.selectorRemove).remove();
|
||||
} else {
|
||||
$row = ( /tr\>/.test(message) ? $(message) : $('<tr><td colspan="' + c.columns + '">' + message + '</td></tr>') )
|
||||
.click(function(){
|
||||
$(this).remove();
|
||||
})
|
||||
// add error row to thead instead of tbody, or clicking on the header will result in a parser error
|
||||
.appendTo( c.$table.find('thead:first') )
|
||||
.addClass( errorRow + ' ' + c.selectorRemove.replace(/^[.#]/, '') )
|
||||
.attr({
|
||||
role : 'alert',
|
||||
'aria-live' : 'assertive'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
Loading…
Reference in New Issue
Block a user