mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Core: update config.totalRows variable before initialization. Fixes #670
This commit is contained in:
parent
26493ec8bc
commit
ed5a86ffad
@ -4996,24 +4996,17 @@ $('.tablesorter')[0].config.cache[0].normalized[0];
|
||||
<tr id="variable-totalrows">
|
||||
<td><a href="#" class="permalink">config.totalRows</a></td>
|
||||
<td>Numeric</td>
|
||||
<td>This variable contains the total number of rows within the table, not including rows within info-only tbodies (<span class="version">v2.17.4</span>)
|
||||
<td>This variable contains the total number of rows within the table, not including rows within info-only tbodies (<span class="version">v2.17.4</span>; <span class="version updated">v2.17.5</span>)
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
Access this internal value at after tablesorter has initialized. It is also included as a variable in the <code>filterEnd</code> event so you can update an external count like this:
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterEnd', function(event, data){
|
||||
Access this internal value after tablesorter has initialized. It is also included as a variable in the <code>filterEnd</code> event so you can update an external count like this:
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterInit filterEnd', function(event, data){
|
||||
// use data.filteredRows or this.config.filteredRows
|
||||
$('.filter-rows').html( data.filteredRows );
|
||||
$('.total-rows').html( data.totalRows );
|
||||
});</pre>The <code>filterEnd</code> event does not fire during filter widget initialization, so if you need to force a search, add this code to the table initialziation to get a <code>filterEnd</code> even to fire (for now):
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
$('table').tablesorter({
|
||||
initialized: function(table){
|
||||
$.tablesorter.setFilters( table, false, true );
|
||||
}
|
||||
});
|
||||
});</pre><hr>
|
||||
If using the pager plugin or widget, the value returned from the <code>filterEnd</code> event will not be accurate, so you'll need to bind to the <code>pagerComplete</code> event instead:
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterEnd pagerComplete', function(event, data){
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterInit filterEnd pagerComplete', function(event, data){
|
||||
// Note: data = table.config (filterEnd event); and data = table.config.pager (pagerComplete event)
|
||||
// both objects contain data.filteredRows & data.totalRows
|
||||
$('.filter-rows').html( data.filteredRows );
|
||||
@ -5096,26 +5089,19 @@ var wo = $('#mytable').data('tablesorter').widgetOptions;
|
||||
<tr id="variable-filteredrows">
|
||||
<td><a href="#" class="permalink">config.filteredRows</a></td>
|
||||
<td>Numeric</td>
|
||||
<td>Only available when the filter widget is active. This variable contains the current number of filtered rows (<span class="version">v2.17.4</span>)
|
||||
<td>Only available when the filter widget is active. This variable contains the current number of filtered rows (<span class="version">v2.17.4</span>; <span class="version updated">v2.17.5</span>)
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
This internal value will show an accurate number of filtered rows; which means the count won't include any rows from "information-only" tbodies.<br>
|
||||
<br>
|
||||
Access this internal value at any time after the filter widget has initialized, or as a shortcut it is included as a variable in the <code>filterEnd</code> event so you can update an external count like this:
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterEnd', function(event, data){
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterInit filterEnd', function(event, data){
|
||||
// use data.filteredRows or this.config.filteredRows
|
||||
$('.filter-rows').html( data.filteredRows );
|
||||
$('.total-rows').html( data.totalRows );
|
||||
});</pre>The <code>filterEnd</code> event does not fire during filter widget initialization, so if you need to force a search, add this code to the table initialziation to get a <code>filterEnd</code> even to fire (for now):
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
$('table').tablesorter({
|
||||
initialized: function(table){
|
||||
$.tablesorter.setFilters( table, false, true );
|
||||
}
|
||||
});
|
||||
});</pre><hr>
|
||||
If using the pager plugin or widget, the value returned from the <code>filterEnd</code> event will not be accurate, so you'll need to bind to the <code>pagerComplete</code> event instead:
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterEnd pagerComplete', function(event, data){
|
||||
<pre class="prettyprint lang-js">$('table').bind('filterInit filterEnd pagerComplete', function(event, data){
|
||||
// Note: data = table.config (filterEnd event); and data = table.config.pager (pagerComplete event)
|
||||
// both objects contain data.filteredRows & data.totalRows
|
||||
$('.filter-rows').html( data.filteredRows );
|
||||
|
@ -274,6 +274,7 @@
|
||||
$tb = c.$table.children('tbody'),
|
||||
parsers = c.parsers;
|
||||
c.cache = {};
|
||||
c.totalRows = 0;
|
||||
// if no parsers found, return - it's an empty table.
|
||||
if (!parsers) {
|
||||
return c.debug ? log('Warning: *Empty table!* Not building a cache') : '';
|
||||
@ -343,6 +344,8 @@
|
||||
cc.normalized.push(cols);
|
||||
}
|
||||
cc.colMax = colMax;
|
||||
// total up rows, not including child rows
|
||||
c.totalRows += cc.normalized.length;
|
||||
}
|
||||
}
|
||||
if (c.showProcessing) {
|
||||
@ -1043,6 +1046,8 @@
|
||||
fixColumnWidth(table);
|
||||
// try to auto detect column type, and store in tables config
|
||||
buildParserCache(table);
|
||||
// start total row count at zero
|
||||
c.totalRows = 0;
|
||||
// build the cache for the tbody cells
|
||||
// delayInit will delay building the cache until the user starts a sort
|
||||
if (!c.delayInit) { buildCache(table); }
|
||||
|
Loading…
Reference in New Issue
Block a user