mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Add filter_hideEmpty; Correct pager & widget updating. Fixes #450.
When all rows are removed from the table, ensure widgets are applied (including refreshing the filter search), and ensure the pager display updates. Add filter_hideEmpty option to allow setting hiding the filter row when the table doesn't contain any tbody rows.
This commit is contained in:
parent
9598bc87ac
commit
396952b57a
@ -116,8 +116,8 @@
|
||||
d = p.cssDisabled,
|
||||
dis = !!disable,
|
||||
first = ( dis || p.page === 0 ),
|
||||
last = ( dis || p.page === tp - 1 || p.totalPages === 0 ),
|
||||
tp = Math.min( p.totalPages, p.filteredPages );
|
||||
tp = Math.min( p.totalPages, p.filteredPages ),
|
||||
last = ( dis || (p.page === tp - 1) || p.totalPages === 0 );
|
||||
if ( p.updateArrows ) {
|
||||
p.$container.find(p.cssFirst + ',' + p.cssPrev)[ first ? a : r ](d).attr('aria-disabled', first);
|
||||
p.$container.find(p.cssNext + ',' + p.cssLast)[ last ? a : r ](d).attr('aria-disabled', last);
|
||||
@ -603,6 +603,8 @@
|
||||
p.size = $.data(table, 'pagerLastSize') || p.size || 10;
|
||||
p.totalPages = Math.ceil( p.totalRows / p.size );
|
||||
renderTable(table, rows, p);
|
||||
// update display here in case all rows are removed
|
||||
updatePageDisplay(table, p, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1508,6 +1508,8 @@ $(function(){
|
||||
filter_formatter : null,
|
||||
// add custom filter functions using this option.
|
||||
filter_functions : null,
|
||||
// hide filter row when table is empty
|
||||
filter_hideEmpty : true,
|
||||
// if true, the filter row is hidden initially until hovered/focused.
|
||||
filter_hideFilters : false,
|
||||
// if true, make all searches case-insensitive.
|
||||
@ -2083,6 +2085,29 @@ $(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>
|
||||
<td>true</td>
|
||||
<td>
|
||||
Filter widget: Set this option to <code>false</code> to always show the filter row; by default, the filter row is completely hidden when no rows exist within the tbody (<span class="version">v2.15</span>).
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
Use the <a href="#widget-filter-hideempty"><code>filter_hideEmpty</code></a> option as follows:
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
$("table").tablesorter({
|
||||
widgets: ["filter"],
|
||||
widgetOptions : {
|
||||
filter_hideEmpty : false
|
||||
}
|
||||
});
|
||||
});</pre></div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr id="widget-filter-hidefilters">
|
||||
<td><a href="#" class="permalink">filter_hideFilters</a></td>
|
||||
<td>Boolean</td>
|
||||
|
@ -327,7 +327,11 @@
|
||||
c2 = c.cache,
|
||||
r, n, totalRows, checkCell, $bk, $tb,
|
||||
i, j, k, l, pos, appendTime;
|
||||
if (isEmptyObject(c2)) { return; } // empty table - fixes #206/#346
|
||||
// empty table - fixes #206/#346
|
||||
if (isEmptyObject(c2)) {
|
||||
// run pager appender in case the table was just emptied
|
||||
return c.appender ? c.appender(table, rows) : '';
|
||||
}
|
||||
if (c.debug) {
|
||||
appendTime = new Date();
|
||||
}
|
||||
|
@ -355,6 +355,7 @@ ts.addWidget({
|
||||
filter_filteredRow : 'filtered', // class added to filtered rows; needed by pager plugin
|
||||
filter_formatter : null, // add custom filter elements to the filter row
|
||||
filter_functions : null, // add custom filter functions using this option
|
||||
filter_hideEmpty : true, // hide filter row when table is empty
|
||||
filter_hideFilters : false, // collapse filter row when mouse leaves the area
|
||||
filter_ignoreCase : true, // if true, make all searches case-insensitive
|
||||
filter_liveSearch : true, // if true, search column content while the user types (with a delay)
|
||||
@ -369,9 +370,7 @@ ts.addWidget({
|
||||
},
|
||||
format: function(table, c, wo) {
|
||||
if (!c.$table.hasClass('hasFilters')) {
|
||||
if (c.parsers || !c.parsers && wo.filter_serversideFiltering) {
|
||||
ts.filter.init(table, c, wo);
|
||||
}
|
||||
ts.filter.init(table, c, wo);
|
||||
}
|
||||
},
|
||||
remove: function(table, c, wo) {
|
||||
@ -560,7 +559,8 @@ ts.filter = {
|
||||
}
|
||||
|
||||
c.$table.bind('addRows updateCell update updateRows updateComplete appendCache filterReset filterEnd search '.split(' ').join('.tsfilter '), function(event, filter) {
|
||||
if ( !/(search|filterReset|filterEnd)/.test(event.type) ) {
|
||||
c.$table.find('.' + ts.css.filterRow).toggle( !(wo.filter_hideEmpty && $.isEmptyObject(c.cache)) ); // fixes #450
|
||||
if ( !/(search|filter)/.test(event.type) ) {
|
||||
event.stopPropagation();
|
||||
ts.filter.buildDefault(table, true);
|
||||
}
|
||||
@ -571,6 +571,10 @@ ts.filter = {
|
||||
} else {
|
||||
// send false argument to force a new search; otherwise if the filter hasn't changed, it will return
|
||||
filter = event.type === 'search' ? filter : event.type === 'updateComplete' ? c.$table.data('lastSearch') : '';
|
||||
if (/(update|add)/.test(event.type)) {
|
||||
// force a new search since content has changed
|
||||
c.lastCombinedFilter = null;
|
||||
}
|
||||
// pass true (dontSkip) to prevent the tablesorter.setFilters function from skipping the first input
|
||||
// ensures all inputs are updated when a search is triggered on the table $('table').trigger('search', [...]);
|
||||
ts.filter.searching(table, filter, true);
|
||||
|
@ -301,10 +301,10 @@ tsp = ts.pager = {
|
||||
var p = c.pager,
|
||||
dis = !!disable,
|
||||
first = dis || p.page === 0,
|
||||
tp = Math.min( p.totalPages, p.filteredPages ),
|
||||
last = dis || p.page === tp - 1 || p.totalPages === 0,
|
||||
wo = c.widgetOptions,
|
||||
s = wo.pager_selectors,
|
||||
tp = Math.min( p.totalPages, p.filteredPages );
|
||||
s = wo.pager_selectors;
|
||||
if ( wo.pager_updateArrows ) {
|
||||
p.$container.find(s.first + ',' + s.prev).toggleClass(wo.pager_css.disabled, first).attr('aria-disabled', first);
|
||||
p.$container.find(s.next + ',' + s.last).toggleClass(wo.pager_css.disabled, last).attr('aria-disabled', last);
|
||||
@ -695,7 +695,10 @@ tsp = ts.pager = {
|
||||
// don't allow rendering multiple times on the same page/size/totalpages/filters/sorts
|
||||
if ( l.page === p.page && l.size === p.size && l.totalPages === p.totalPages &&
|
||||
(l.currentFilters || []).join(',') === (p.currentFilters || []).join(',') &&
|
||||
l.sortList === (c.sortList || []).join(',') ) { return; }
|
||||
l.sortList === (c.sortList || []).join(',') ) {
|
||||
// make sure widgets are applied - fixes #450
|
||||
return flag === true ? c.$table.trigger('applyWidgets') : '';
|
||||
}
|
||||
if (c.debug) {
|
||||
ts.log('Pager changing to page ' + p.page);
|
||||
}
|
||||
@ -801,7 +804,9 @@ tsp = ts.pager = {
|
||||
p.totalRows = c.widgetOptions.pager_countChildRows ? c.$tbodies.eq(0).children().length : rows.length;
|
||||
p.size = $.data(table, 'pagerLastSize') || p.size || wo.pager_size || 10;
|
||||
p.totalPages = Math.ceil( p.totalRows / p.size );
|
||||
tsp.moveToPage(table, p);
|
||||
tsp.moveToPage(table, p, true);
|
||||
// update display here in case all rows are removed
|
||||
tsp.updatePageDisplay(table, c, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user