Core: add rowFilter parameter to getColumnText

This commit is contained in:
Rob Garrison 2015-10-19 20:54:56 -05:00
parent 9d7f0fb26c
commit d5a9fb6f81
11 changed files with 45 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/*! tablesorter (FORK) - updated 10-18-2015 (v2.23.5)*/
/*! tablesorter (FORK) - updated 10-19-2015 (v2.23.5)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -940,7 +940,7 @@
}
},
getColumnText : function( table, column, callback ) {
getColumnText : function( table, column, callback, rowFilter ) {
table = $( table )[0];
var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
hasCallback = typeof callback === 'function',
@ -957,8 +957,11 @@
cache = c.cache[ tbodyIndex ].normalized;
rowLen = cache.length;
for ( rowIndex = 0; rowIndex < rowLen; rowIndex++ ) {
row = cache[ rowIndex ];
if ( rowFilter && !row[ c.columns ].$row.is( rowFilter ) ) {
continue;
}
result = true;
row = cache[ rowIndex ];
parsed = ( allColumns ) ? row.slice( 0, c.columns ) : row[ column ];
row = row[ c.columns ];
raw = ( allColumns ) ? row.raw : row.raw[ column ];

File diff suppressed because one or more lines are too long

View File

@ -938,7 +938,7 @@
}
},
getColumnText : function( table, column, callback ) {
getColumnText : function( table, column, callback, rowFilter ) {
table = $( table )[0];
var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
hasCallback = typeof callback === 'function',
@ -955,8 +955,11 @@
cache = c.cache[ tbodyIndex ].normalized;
rowLen = cache.length;
for ( rowIndex = 0; rowIndex < rowLen; rowIndex++ ) {
row = cache[ rowIndex ];
if ( rowFilter && !row[ c.columns ].$row.is( rowFilter ) ) {
continue;
}
result = true;
row = cache[ rowIndex ];
parsed = ( allColumns ) ? row.slice( 0, c.columns ) : row[ column ];
row = row[ c.columns ];
raw = ( allColumns ) ? row.raw : row.raw[ column ];

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! tablesorter (FORK) - updated 10-18-2015 (v2.23.5)*/
/*! tablesorter (FORK) - updated 10-19-2015 (v2.23.5)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {

File diff suppressed because one or more lines are too long

View File

@ -32,7 +32,7 @@ pre.lang-js, pre.lang-javascript {border-left-color: #f1bf26;}
pre.lang-html {border-left-color: #ef6328;}
pre.lang-css {border-left-color: #27aae2;}
pre,#display {background-color:#eee;font-size:small;list-style:none;}
pre.prettyprint {padding:5px;}
pre.prettyprint {padding:5px; white-space: pre-wrap; word-break: break-all; }
code {background-color: #e6e6e6; padding: 1px 5px;}
a code {text-decoration:underline;}
pre.normal {background-color:transparent;border:none;border-left-width:0;overflow-x:auto;}

View File

@ -6832,15 +6832,16 @@ textExtractionFunction = $.tablesorter.getColumnData( table, table.config.textEx
<tr id="function-getcolumntext">
<td><a href="#" class="permalink">getColumnText</a></td>
<td>This utility function returns the entire column text (raw and parsed) as well as other data (<span class="version">v2.21.4</span>).
<td>This utility function returns the entire column text (raw and parsed) as well as other data (<span class="version">v2.21.4</span>; <span class="updated version">v2.23.6</span>).
<div class="collapsible">
<br>
Use it as follows:
<pre class="prettyprint lang-js">$.tablesorter.getColumnText( table, column, callback );</pre>
<pre class="prettyprint lang-js">$.tablesorter.getColumnText( table, column, callback, rowFilter );</pre>
<ul>
<li><code>table</code> - table DOM element (or jQuery object).</li>
<li><code>column</code> - zero-based column index or <code>'all'</code>.</li>
<li><code>callback</code> - callback function that is called while obtaining data for each cell within the specified column.</li>
<li><code>rowFilter</code> - can be a jQuery selector, function or element to allow targeting specific rows (e.g. <code>":visible"</code> or <code>":not(.child-row)"</code>); this parameter is used in a jQuery <code><a class="external" href="http://api.jquery.com/is/">.is()</a></code> function (<span class="version">v2.23.6</span>).</li>
</ul>
When using the callback, there is only one argument (object) passed to this function; it contains the following:
<ul>
@ -6881,6 +6882,16 @@ $.tablesorter.getColumnText( table, 3, function( data ) {
// parsed : [ 'cell1', 'cell2', ..., 'celln' ],
// $cell : [ $cell1, $cell2, ..., $celln ]
// }
</pre>
When using the filter widget, you can ignore filtered rows using the following code:
<pre class="prettyprint lang-js">var table = $('table')[0],
// targeting the 4th column (zero-based index); callback function is an empty string & therefore ignored
columnText = $.tablesorter.getColumnText( table, 3, '', ':not(.filtered)' );
// columnText = {
// raw : [ 'cell1', 'cell2', ..., 'celln' ],
// parsed : [ 'cell1', 'cell2', ..., 'celln' ],
// $cell : [ $cell1, $cell2, ..., $celln ]
// }
</pre>
All of these methods of gathering column data might be useful for custom widgets, etc.
<p></p>

View File

@ -4,7 +4,7 @@
*/
/*! tablesorter (FORK) - updated 10-18-2015 (v2.23.5)*/
/*! tablesorter (FORK) - updated 10-19-2015 (v2.23.5)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -946,7 +946,7 @@
}
},
getColumnText : function( table, column, callback ) {
getColumnText : function( table, column, callback, rowFilter ) {
table = $( table )[0];
var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
hasCallback = typeof callback === 'function',
@ -963,8 +963,11 @@
cache = c.cache[ tbodyIndex ].normalized;
rowLen = cache.length;
for ( rowIndex = 0; rowIndex < rowLen; rowIndex++ ) {
row = cache[ rowIndex ];
if ( rowFilter && !row[ c.columns ].$row.is( rowFilter ) ) {
continue;
}
result = true;
row = cache[ rowIndex ];
parsed = ( allColumns ) ? row.slice( 0, c.columns ) : row[ column ];
row = row[ c.columns ];
raw = ( allColumns ) ? row.raw : row.raw[ column ];

View File

@ -928,7 +928,7 @@
}
},
getColumnText : function( table, column, callback ) {
getColumnText : function( table, column, callback, rowFilter ) {
table = $( table )[0];
var tbodyIndex, rowIndex, cache, row, tbodyLen, rowLen, raw, parsed, $cell, result,
hasCallback = typeof callback === 'function',
@ -945,8 +945,11 @@
cache = c.cache[ tbodyIndex ].normalized;
rowLen = cache.length;
for ( rowIndex = 0; rowIndex < rowLen; rowIndex++ ) {
row = cache[ rowIndex ];
if ( rowFilter && !row[ c.columns ].$row.is( rowFilter ) ) {
continue;
}
result = true;
row = cache[ rowIndex ];
parsed = ( allColumns ) ? row.slice( 0, c.columns ) : row[ column ];
row = row[ c.columns ];
raw = ( allColumns ) ? row.raw : row.raw[ column ];

View File

@ -4,7 +4,7 @@
*/
/*! tablesorter (FORK) - updated 10-18-2015 (v2.23.5)*/
/*! tablesorter (FORK) - updated 10-19-2015 (v2.23.5)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {