mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Output: output_callback can now return modified data. Fixes #1121
This commit is contained in:
parent
5992cb6649
commit
fa45fea896
@ -135,9 +135,11 @@ table.tablesorter tbody tr.even.checked td {
|
||||
// callbackJSON used when outputting JSON & any header cells has a colspan - unique names required
|
||||
output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + cellIndex + ')'; },
|
||||
// callback executed when processing completes
|
||||
// return true to continue download/output
|
||||
output_callback : function(config, data) {
|
||||
// return false to stop delivery & do something else with the data
|
||||
output_callback : function(config, data) { return true; },
|
||||
// return true OR modified data (v2.25.1) to continue download/output
|
||||
return true;
|
||||
},
|
||||
|
||||
// the need to modify this for Excel no longer exists
|
||||
output_encoding : 'data:application/octet-stream;charset=utf8,'
|
||||
@ -245,6 +247,7 @@ table.tablesorter tbody tr.even.checked td {
|
||||
|
||||
<h4>Changes</h4>
|
||||
<ul>
|
||||
<li>In <span class="version">v2.25.1</span>, the <code>output_callback</code> can return modified data instead of a boolean.</li>
|
||||
<li>In <span class="version">v2.22.4</span>, added <code>output_formatContent</code> callback function which allows for extra formatting of cell content (e.g. convert <code>'&amp;'</code> → <code>'&'</code>).</li>
|
||||
<li>In <span class="version">v2.22.2</span>,
|
||||
<ul>
|
||||
@ -739,16 +742,20 @@ line,value1,value2,value3
|
||||
<tr id="output_callback">
|
||||
<td><a href="#" class="permalink">output_callback</a></td>
|
||||
<td>{see description}</td>
|
||||
<td>Return <code>true</code> in this callback to continue the download or open the popup (<span class="version updated">v2.17.0</span>).
|
||||
<td>Return <code>true</code> or modified data in this callback to continue the download or open the popup (<span class="version updated">v2.25.1</span>).
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
As of v2.17.0, the callback function was modified to pass two parameters:
|
||||
<p>In <span class="version">v2.25.1</span>, this callback can return modified data for output.</p>
|
||||
<p>As of v2.17.0, the callback function was modified to pass two parameters:</p>
|
||||
<ul>
|
||||
<li><code>config</code> - the <code>table.config</code> settings.</li>
|
||||
<li><code>data</code> - the output data as a string</li>
|
||||
</ul>
|
||||
Default setting:
|
||||
<pre class="prettyprint lang-js">function(config, data){ return true; }</pre>
|
||||
<pre class="prettyprint lang-js">function(config, data){
|
||||
// return data.replace( /Mary Smith/g, 'Mary Smith-Jones' ); // v2.25.1+
|
||||
return true;
|
||||
}</pre>
|
||||
After table processing has completed, this callback function is exectued. If <code>true</code> is not returned, the processed data will not open a popup, nor download the data.
|
||||
<pre class="prettyprint lang-js">output_callback : function(config, data) {
|
||||
// send output to the console only
|
||||
|
@ -483,7 +483,7 @@
|
||||
<li><span class="label label-info">Beta</span> <a href="example-widget-lazyload.html">Lazyload widget</a> (<span class="version">v2.24.0</span>).</li>
|
||||
<li><a href="example-widget-math.html">Math widget</a> (<span class="version">v2.16</span>; <span class="version updated">v2.25.0</span>).</li>
|
||||
<li>
|
||||
<a href="example-widget-output.html">Output widget</a> (<span class="version">v2.16</span>; <span class="version updated">v2.24.0</span>).
|
||||
<a href="example-widget-output.html">Output widget</a> (<span class="version">v2.16</span>; <span class="version updated">v2.25.1</span>).
|
||||
<br><br>
|
||||
</li>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*! Widget: output - updated 10/31/2015 (v2.24.0) *//*
|
||||
/*! Widget: output - updated 1/10/2016 (v2.25.1) *//*
|
||||
* Requires tablesorter v2.8+ and jQuery 1.7+
|
||||
* Modified from:
|
||||
* HTML Table to CSV: http://www.kunalbabre.com/projects/table2CSV.php (License unknown?)
|
||||
@ -189,7 +189,14 @@
|
||||
}
|
||||
|
||||
// callback; if true returned, continue processing
|
||||
if ($.isFunction(wo.output_callback) && !wo.output_callback(c, mydata)) { return; }
|
||||
if ($.isFunction(wo.output_callback)) {
|
||||
tmp = wo.output_callback(c, mydata);
|
||||
if ( tmp === false ) {
|
||||
return;
|
||||
} else if ( typeof tmp === 'string' ) {
|
||||
mydata = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if ( /p/i.test( wo.output_delivery || '' ) ) {
|
||||
output.popup(mydata, wo.output_popupStyle, outputJSON || outputArray);
|
||||
|
Loading…
Reference in New Issue
Block a user