Output: Add output_includeHeader option & docs. Fixes #1349

This commit is contained in:
Rob Garrison 2017-01-02 07:26:33 -06:00
parent 39430d5773
commit 0da52de497
2 changed files with 168 additions and 84 deletions

View File

@ -42,7 +42,7 @@
text-align: right; text-align: right;
margin-right: 4px; margin-right: 4px;
} }
div.output-download-popup { .dropdown-menu li div {
margin-bottom: 5px; margin-bottom: 5px;
} }
.output-separator, .output-replacequotes, .output-quotes { .output-separator, .output-replacequotes, .output-quotes {
@ -91,7 +91,7 @@ table.tablesorter tbody tr.even.checked td {
// buttons set up like this: // buttons set up like this:
// <button type="button" data-filter-column="4" data-filter-text="2?%">Saved Search</button> // <button type="button" data-filter-column="4" data-filter-text="2?%">Saved Search</button>
$('button[data-filter-column]').click(function(){ $('button[data-filter-column]').click(function(){
/*** first method *** data-filter-column="1" data-filter-text="!son" /*** first method *** data-filter-column="2" data-filter-text="!son"
add search value to Discount column (zero based index) input */ add search value to Discount column (zero based index) input */
var filters = [], var filters = [],
$t = $(this), $t = $(this),
@ -117,12 +117,14 @@ table.tablesorter tbody tr.even.checked td {
widgetOptions : { widgetOptions : {
filter_filteredRow : 'filtered', filter_filteredRow : 'filtered',
filter_reset : '.group1 .reset', filter_reset : '.group1 .reset',
output_separator : ',', // ',' 'json', 'array' or separator (e.g. ';') output_separator : ',', // ',' 'json', 'array' or separator (e.g. ';')
output_ignoreColumns : [0], // columns to ignore [0, 1,... ] (zero-based index) output_ignoreColumns : [0], // columns to ignore [0, 1,... ] (zero-based index)
output_hiddenColumns : false, // include hidden columns in the output output_hiddenColumns : false, // include hidden columns in the output
output_includeFooter : true, // include footer rows in the output output_includeFooter : true, // include footer rows in the output
output_includeHeader : true, // include header rows in the output
output_headerRows : false // output all header rows (if multiple rows)
output_dataAttrib : 'data-name', // data-attribute containing alternate cell text output_dataAttrib : 'data-name', // data-attribute containing alternate cell text
output_headerRows : true, // output all header rows (multiple rows)
output_delivery : 'p', // (p)opup, (d)ownload output_delivery : 'p', // (p)opup, (d)ownload
output_saveRows : 'f', // (a)ll, (v)isible, (f)iltered, jQuery filter selector (string only) or filter function output_saveRows : 'f', // (a)ll, (v)isible, (f)iltered, jQuery filter selector (string only) or filter function
output_duplicateSpans: true, // duplicate output data in tbody colspan/rowspan output_duplicateSpans: true, // duplicate output data in tbody colspan/rowspan
@ -133,7 +135,9 @@ table.tablesorter tbody tr.even.checked td {
output_popupStyle : 'width=580,height=310', output_popupStyle : 'width=580,height=310',
output_saveFileName : 'mytable.csv', output_saveFileName : 'mytable.csv',
// callbackJSON used when outputting JSON & any header cells has a colspan - unique names required // callbackJSON used when outputting JSON & any header cells has a colspan - unique names required
output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + cellIndex + ')'; }, output_callbackJSON : function($cell, txt, cellIndex) {
return txt + '(' + cellIndex + ')';
},
// callback executed when processing completes // callback executed when processing completes
output_callback : function(config, data, url) { output_callback : function(config, data, url) {
// return false to stop delivery & do something else with the data // return false to stop delivery & do something else with the data
@ -142,8 +146,13 @@ table.tablesorter tbody tr.even.checked td {
}, },
// the need to modify this for Excel no longer exists // the need to modify this for Excel no longer exists
output_encoding : 'data:application/octet-stream;charset=utf8,' output_encoding : 'data:application/octet-stream;charset=utf8,',
// override internal save file code and use an external plugin such as
// https://github.com/eligrey/FileSaver.js
output_savePlugin : null /* function(config, widgetOptions, data) {
var blob = new Blob([data], {type: widgetOptions.output_encoding});
saveAs(blob, widgetOptions.output_saveFileName);
} */
} }
}).tablesorterPager({ }).tablesorterPager({
container: $('.ts-pager'), container: $('.ts-pager'),
@ -180,7 +189,7 @@ table.tablesorter tbody tr.even.checked td {
// make separator & replace quotes buttons update the value // make separator & replace quotes buttons update the value
$this.find('.output-separator').click(function(){ $this.find('.output-separator').click(function(){
$this.find('.output-separator').removeClass('active'); $this.find('.output-separator').removeClass('active');
var txt = $(this).addClass('active').html() var txt = $(this).addClass('active').html();
$this.find('.output-separator-input').val( txt ); $this.find('.output-separator-input').val( txt );
$this.find('.output-filename').val(function(i, v){ $this.find('.output-filename').val(function(i, v){
// change filename extension based on separator // change filename extension based on separator
@ -195,27 +204,42 @@ table.tablesorter tbody tr.even.checked td {
$this.find('.output-replacequotes').val( $(this).addClass('active').text() ); $this.find('.output-replacequotes').val( $(this).addClass('active').text() );
return false; return false;
}); });
// header/footer toggle buttons
$this.find('.output-header, .output-footer').click(function(){
$(this).toggleClass('active');
});
// clicking the download button; all you really need is to // clicking the download button; all you really need is to
// trigger an "output" event on the table // trigger an "output" event on the table
$this.find('.download').click(function(){ $this.find('.download').click(function(){
var typ, var typ,
$table = $this.find('table'), $table = $this.find('table'),
wo = $table[0].config.widgetOptions, wo = $table[0].config.widgetOptions,
saved = $this.find('.output-filter-all :checked').attr('class'); val = $this.find('.output-filter-all :checked').attr('class');
wo.output_separator = $this.find('.output-separator-input').val(); wo.output_saveRows = val === 'output-filter' ? 'f' :
wo.output_delivery = $this.find('.output-download-popup :checked').attr('class') === 'output-download' ? 'd' : 'p'; val === 'output-visible' ? 'v' :
wo.output_saveRows = saved === 'output-filter' ? 'f' : // checked class name, see table.config.checkboxClass
saved === 'output-visible' ? 'v' : val === 'output-selected' ? '.checked' :
saved === 'output-selected' ? '.checked' : // checked class name, see table.config.checkboxClass val === 'output-sel-vis' ? '.checked:visible' :
saved === 'output-sel-vis' ? '.checked:visible' :
'a'; 'a';
val = $this.find('.output-download-popup :checked').attr('class');
wo.output_delivery = val === 'output-download' ? 'd' : 'p';
wo.output_separator = $this.find('.output-separator-input').val();
wo.output_replaceQuote = $this.find('.output-replacequotes').val(); wo.output_replaceQuote = $this.find('.output-replacequotes').val();
wo.output_trimSpaces = $this.find('.output-trim').is(':checked'); wo.output_trimSpaces = $this.find('.output-trim').is(':checked');
wo.output_includeHTML = $this.find('.output-html').is(':checked'); wo.output_includeHTML = $this.find('.output-html').is(':checked');
wo.output_wrapQuotes = $this.find('.output-wrap').is(':checked'); wo.output_wrapQuotes = $this.find('.output-wrap').is(':checked');
wo.output_headerRows = $this.find('.output-headers').is(':checked');
wo.output_saveFileName = $this.find('.output-filename').val(); wo.output_saveFileName = $this.find('.output-filename').val();
// first example buttons, second has radio buttons
if (groupIndex === 0) {
wo.output_includeHeader = $this.find('button.output-header').is(".active");
} else {
wo.output_includeHeader = !$this.find('.output-no-header').is(':checked');
wo.output_headerRows = $this.find('.output-headers').is(':checked');
}
// footer not included in second example
wo.output_includeFooter = $this.find('.output-footer').is(".active");
$table.trigger('outputTable'); $table.trigger('outputTable');
return false; return false;
}); });
@ -247,10 +271,23 @@ table.tablesorter tbody tr.even.checked td {
<h4>Changes</h4> <h4>Changes</h4>
<ul> <ul>
<li>In <span class="version">v2.27.0</span>, the <code>output_callback</code> now includes a <code>url</code> parameter.</li> <li>In <span class="version">v2.28.4</span>,
<li>In <span class="version">v2.25.2</span>, updated the <code>output_saveRows</code> option to accept a function.</li> <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>Added <a class="intlink" href="#output_includeheader"><code>output_includeHeader</code></a> option.</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;amp;'</code> &rarr; <code>'&amp;'</code>).</li> <li>Added <a class="intlink" href="#output_saveplugin"><code>output_savePlugin</code></a> option.</li>
<li>Prevent javascript error while attempting to update an already open popup window.</li>
</ul>
</li>
<li>In <span class="version">v2.27.0</span>, the <a class="intlink" href="#output_callback"><code>output_callback</code></a> now includes a <code>url</code> parameter.</li>
<li>In <span class="version">v2.25.2</span>, updated the <a class="intlink" href="#output_saverows"><code>output_saveRows</code></a> option to accept a function.</li>
<li>In <span class="version">v2.25.1</span>, the <a class="intlink" href="#output_callback"><code>output_callback</code></a> can return modified data instead of a boolean.</li>
<li>In <span class="version">v2.22.4</span>, added <a class="intlink" href="#output_formatcontent"><code>output_formatContent</code></a> callback function which allows for extra formatting of cell content (e.g. convert <code>'&amp;amp;'</code> &rarr; <code>'&amp;'</code>).</li>
</ul>
<div class="accordion start-closed">
<h3 id="old-notes"><a href="#">Older Notes</a></h3>
<div>
<ul>
<li>In <span class="version">v2.22.2</span>, <li>In <span class="version">v2.22.2</span>,
<ul> <ul>
<li>The data-attribute used by the <code>output_dataAttrib</code> can now be an empty string.</li> <li>The data-attribute used by the <code>output_dataAttrib</code> can now be an empty string.</li>
@ -275,12 +312,14 @@ table.tablesorter tbody tr.even.checked td {
<li>In <span class="version">v2.17.5</span>, the need to modify the server's content disposition no longer exists.</li> <li>In <span class="version">v2.17.5</span>, the need to modify the server's content disposition no longer exists.</li>
<li>In <span class="version">v2.17.0</span>, <li>In <span class="version">v2.17.0</span>,
<ul> <ul>
<li>Added the <code>output_ignoreColumns</code> option &amp; modified the <code>output_callback</code> parameters.</li> <li>Added the <code>output_ignoreColumns</code> option &amp; modified the <a class="intlink" href="#output_callback"><code>output_callback</code></a> parameters.</li>
<li>Added <code>output_duplicateSpans</code> option to duplicate (when <code>true</code>) colspan &amp; rowspan content across cells.</li> <li>Added <code>output_duplicateSpans</code> option to duplicate (when <code>true</code>) colspan &amp; rowspan content across cells.</li>
</ul> </ul>
</li> </li>
<li>In <span class="version">v2.16.4</span>, added the <code>output_encoding</code> option.</li> <li>In <span class="version">v2.16.4</span>, added the <code>output_encoding</code> option.</li>
</ul> </ul>
</div>
</div>
<h4>Requirements</h4> <h4>Requirements</h4>
<ul> <ul>
@ -453,7 +492,7 @@ line,value1,value2,value3
<br> <br>
When the output is created, and it this option doesn't match either <code>&quot;json&quot;</code> or <code>&quot;array&quot;</code>, each block of table cell data will be separated by this setting.<br> When the output is created, and it this option doesn't match either <code>&quot;json&quot;</code> or <code>&quot;array&quot;</code>, each block of table cell data will be separated by this setting.<br>
<br> <br>
This is the result with this option set to <code>&quot;,&quot;</code> and with the table filtered with Rank <button type="button" data-filter-column="0" data-filter-text=">100">&gt;100</button> : This is the result with this option set to <code>&quot;,&quot;</code> and with the table filtered with Rank <button type="button" data-filter-column="1" data-filter-text=">100">&gt;100</button> :
<br> <br>
<pre class="prettyprint lang-js">Rank,First,Last,Age,Total,Discount,Date <pre class="prettyprint lang-js">Rank,First,Last,Age,Total,Discount,Date
111,Peter,Parker,28,$9.99,20%,"Jul 6, 2006 8:14 AM" 111,Peter,Parker,28,$9.99,20%,"Jul 6, 2006 8:14 AM"
@ -516,6 +555,24 @@ line,value1,value2,value3
Change this option to <code>true</code> to include the <code>&lt;tfoot&gt;</code> rows in the output (<span class="version">v2.21.0</span>) Change this option to <code>true</code> to include the <code>&lt;tfoot&gt;</code> rows in the output (<span class="version">v2.21.0</span>)
</td> </td>
</tr> </tr>
<tr id="output_includeheader">
<td><span class="permalink">output_includeHeader</span></td>
<td><code>true</code></td>
<td>
Change this option to <code>false</code> to not include any rows from the <code>&lt;thead&gt;</code> in the output (<span class="version">v2.28.4</span>)
</td>
</tr>
<tr id="output_headerrows">
<td><a href="#" class="permalink">output_headerRows</a></td>
<td><code>false</code></td>
<td>
Setting this option to <code>true</code> will include all header rows while processing a JSON output.
<div class="collapsible">
<br>
If this option is set to <code>false</code>, only the <strong>last row</strong> of the table header will be used as a key names for the tbody values; this does assume that the last table row in the header contains all of the header cell names &amp; does not contain any <code>colspan</code>.
</div>
</td>
</tr>
<tr id="output_dataattrib"> <tr id="output_dataattrib">
<td><a href="#" class="permalink">output_dataAttrib</a></td> <td><a href="#" class="permalink">output_dataAttrib</a></td>
<td><code>'data-name'</code></td> <td><code>'data-name'</code></td>
@ -542,17 +599,6 @@ line,value1,value2,value3
</div> </div>
</td> </td>
</tr> </tr>
<tr id="output_headerrows">
<td><a href="#" class="permalink">output_headerRows</a></td>
<td><code>false</code></td>
<td>
Setting this option to <code>true</code> will include all header rows while processing a JSON output.
<div class="collapsible">
<br>
If this option is set to <code>false</code>, only the <strong>last row</strong> of the table header will be used as a key names for the tbody values; this does assume that the last table row in the header contains all of the header cell names &amp; does not contain any <code>colspan</code>.
</div>
</td>
</tr>
<tr id="output_delivery"> <tr id="output_delivery">
<td><a href="#" class="permalink">output_delivery</a></td> <td><a href="#" class="permalink">output_delivery</a></td>
<td><code>'popup'</code></td> <td><code>'popup'</code></td>
@ -685,7 +731,7 @@ line,value1,value2,value3
This option, if <code>true</code> wrap the output of all table cell content in quotes. This option, if <code>true</code> wrap the output of all table cell content in quotes.
<div class="collapsible"> <div class="collapsible">
<br> <br>
This is the output of the widget when the age column is filtered for results in the range <button type="button" data-filter-column="3" data-filter-text="25 - 35">25 - 35</button>. This is the output of the widget when the age column is filtered for results in the range <button type="button" data-filter-column="4" data-filter-text="25 - 35">25 - 35</button>.
<pre class="prettyprint lang-js">"Rank","First","Last","Age","Total","Discount","Date" <pre class="prettyprint lang-js">"Rank","First","Last","Age","Total","Discount","Date"
"1","Philip Aaron Wong","Johnson Sr Esq","25","$5.95","22%","Jun 26, 2004 7:22 AM" "1","Philip Aaron Wong","Johnson Sr Esq","25","$5.95","22%","Jun 26, 2004 7:22 AM"
"111","Peter","Parker","28","$9.99","20%","Jul 6, 2006 8:14 AM" "111","Peter","Parker","28","$9.99","20%","Jul 6, 2006 8:14 AM"
@ -718,7 +764,6 @@ line,value1,value2,value3
<td><code>'mytable.csv'</code></td> <td><code>'mytable.csv'</code></td>
<td>When downloading, this option sets the filename of the output.</td> <td>When downloading, this option sets the filename of the output.</td>
</tr> </tr>
<tr id="output_formatcontent"> <tr id="output_formatcontent">
<td><a href="#" class="permalink">output_formatContent</a></td> <td><a href="#" class="permalink">output_formatContent</a></td>
<td>null</td> <td>null</td>
@ -836,6 +881,21 @@ output_encoding : 'data:text/csv;charset=utf8,'</pre><span class="label label-in
</td> </td>
</tr> </tr>
<tr id="output_saveplugin">
<td><a href="#" class="permalink">output_savePlugin</a></td>
<td><code>null</code></td>
<td>Override internal save file code and use an external plugin (<span class="version">v2.28.4</span>)
<div class="collapsible">
<br>
<p>You can use a plugin such as <a href="https://github.com/eligrey/FileSaver.js">FileSaver.js</a> instead of the simplified, and possibly out-of-date internal method.</p>
Use this option as follows:
<pre class="prettyprint lang-js">output_savePlugin: function(config, widgetOptions, data) {
var blob = new Blob([data], {type: widgetOptions.output_encoding});
saveAs(blob, widgetOptions.output_saveFileName);
}</pre>
</td>
</tr>
</tbody> </tbody>
</table> </table>
<span class="label label-info">Note</span> If you need to change the carriage return and/or the tab replacement strings, modify them as follows (changed in <span class="version">v2.21.2</span>): <span class="label label-info">Note</span> If you need to change the carriage return and/or the tab replacement strings, modify them as follows (changed in <span class="version">v2.21.2</span>):
@ -851,7 +911,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<h1>Demo</h1> <h1>Demo</h1>
<br> <br>
Search <button type="button" data-filter-column="5" data-filter-text=">15">&gt;15</button> in the Discount column<br> Search <button type="button" data-filter-column="6" data-filter-text=">15">&gt;15</button> in the Discount column<br>
<br> <br>
<div id="demo"><div class="group1"> <div id="demo"><div class="group1">
@ -861,7 +921,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<!-- Split button --> <!-- Split button -->
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default download">Download</button> <button type="button" class="btn btn-default download">Output</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span> <span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
@ -878,6 +938,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<button type="button" class="output-separator btn btn-default btn-xs" title="output Array (see note)">array</button> <button type="button" class="output-separator btn btn-default btn-xs" title="output Array (see note)">array</button>
</li> </li>
<li> <li>
<label>Send to:</label>
<div class="btn-group output-download-popup" data-toggle="buttons" title="Download file or open in Popup window"> <div class="btn-group output-download-popup" data-toggle="buttons" title="Download file or open in Popup window">
<label class="btn btn-default btn-sm active"> <label class="btn btn-default btn-sm active">
<input type="radio" name="delivery1" class="output-popup" checked> Popup <input type="radio" name="delivery1" class="output-popup" checked> Popup
@ -888,6 +949,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
</div> </div>
</li> </li>
<li> <li>
<label>Include:</label>
<div class="btn-group output-filter-all" data-toggle="buttons" title="Output only filtered, visible, selected, selected+visible or all rows"> <div class="btn-group output-filter-all" data-toggle="buttons" title="Output only filtered, visible, selected, selected+visible or all rows">
<label class="btn btn-default btn-sm active"> <label class="btn btn-default btn-sm active">
<input type="radio" name="getrows1" class="output-filter" checked="checked"> Filtered <input type="radio" name="getrows1" class="output-filter" checked="checked"> Filtered
@ -906,6 +968,10 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
</label> </label>
</div> </div>
</li> </li>
<li>
<button class="output-header btn btn-default btn-sm active" title="Include table header">Header</button>
<button class="output-footer btn btn-default btn-sm active" title="Include table footer">Footer</button>
</li>
<li class="divider"></li> <li class="divider"></li>
<li> <li>
<label>Replace quotes: <input class="output-replacequotes" type="text" size="2" value="'" /></label> <label>Replace quotes: <input class="output-replacequotes" type="text" size="2" value="'" /></label>
@ -922,11 +988,11 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
</div> </div>
<div class="ts-pager form-horizontal"> <div class="ts-pager form-horizontal">
<button type="button" class="btn btn-default btn-sm first"><i class="icon-step-backward glyphicon glyphicon-step-backward"></i></button> <button type="button" class="btn btn-default btn-sm first"><i class="glyphicon glyphicon-step-backward"></i></button>
<button type="button" class="btn btn-default btn-sm prev"><i class="icon-arrow-left glyphicon glyphicon-backward"></i></button> <button type="button" class="btn btn-default btn-sm prev"><i class="glyphicon glyphicon-backward"></i></button>
<span class="pagedisplay"></span> <!-- this can be any element, including an input --> <span class="pagedisplay"></span> <!-- this can be any element, including an input -->
<button type="button" class="btn btn-default btn-sm next"><i class="icon-arrow-right glyphicon glyphicon-forward"></i></button> <button type="button" class="btn btn-default btn-sm next"><i class="glyphicon glyphicon-forward"></i></button>
<button type="button" class="btn btn-default btn-sm last"><i class="icon-step-forward glyphicon glyphicon-step-forward"></i></button> <button type="button" class="btn btn-default btn-sm last"><i class="glyphicon glyphicon-step-forward"></i></button>
<select class="pagesize form-control btn-sm" title="Select page size"> <select class="pagesize form-control btn-sm" title="Select page size">
<option selected="selected" value="5">5</option> <option selected="selected" value="5">5</option>
<option value="10">10</option> <option value="10">10</option>
@ -937,7 +1003,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<table id="table" class="tablesorter"> <table id="table" class="tablesorter">
<thead> <thead>
<tr> <tr>
<th class="sorter-checkbox"></th> <th class="sorter-checkbox filter-false">&nbsp;</th>
<th>Rank</th> <th>Rank</th>
<th data-name="First">First Name</th> <th data-name="First">First Name</th>
<th data-name="Last">Last Name</th> <th data-name="Last">Last Name</th>
@ -984,7 +1050,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<!-- Split button --> <!-- Split button -->
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default download">Download</button> <button type="button" class="btn btn-default download">Output</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span> <span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
@ -1001,6 +1067,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<button type="button" class="output-separator btn btn-default btn-xs" title="output Array (see note)">array</button> <button type="button" class="output-separator btn btn-default btn-xs" title="output Array (see note)">array</button>
</li> </li>
<li> <li>
<label>Send to:</label>
<div class="btn-group output-download-popup" data-toggle="buttons" title="Download file or open in Popup window"> <div class="btn-group output-download-popup" data-toggle="buttons" title="Download file or open in Popup window">
<label class="btn btn-default btn-sm active"> <label class="btn btn-default btn-sm active">
<input type="radio" name="delivery2" class="output-popup" checked> Popup <input type="radio" name="delivery2" class="output-popup" checked> Popup
@ -1011,6 +1078,7 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
</div> </div>
</li> </li>
<li> <li>
<label>Include:</label>
<div class="btn-group output-filter-all" data-toggle="buttons" title="Output only filtered, visible or all rows"> <div class="btn-group output-filter-all" data-toggle="buttons" title="Output only filtered, visible or all rows">
<label class="btn btn-default btn-sm active"> <label class="btn btn-default btn-sm active">
<input type="radio" name="getrows2" class="output-filter" checked> Filtered <input type="radio" name="getrows2" class="output-filter" checked> Filtered
@ -1023,6 +1091,20 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
</label> </label>
</div> </div>
</li> </li>
<li>
<label>Header:</label>
<div class="btn-group output-includes" data-toggle="buttons" title="Include no, single (last row), or all table headers">
<label class="btn btn-default btn-sm">
<input type="radio" name="headers" class="output-no-header"> None
</label>
<label class="btn btn-default btn-sm">
<input type="radio" name="headers"> Single
</label>
<label class="btn btn-default btn-sm active">
<input type="radio" name="headers" class="output-headers" checked> All
</label>
</div>
</li>
<li class="divider"></li> <li class="divider"></li>
<li> <li>
<label>Replace quotes: <input class="output-replacequotes" type="text" size="2" value="'" /></label> <label>Replace quotes: <input class="output-replacequotes" type="text" size="2" value="'" /></label>
@ -1033,7 +1115,6 @@ $.tablesorter.output.replaceTab = '\x09';</pre>
<li><label title="Remove extra white space from each cell">Trim spaces: <input class="output-trim" type="checkbox" checked /></label></li> <li><label title="Remove extra white space from each cell">Trim spaces: <input class="output-trim" type="checkbox" checked /></label></li>
<li><label title="Include HTML from cells in output">Include HTML: <input class="output-html" type="checkbox" /></label></li> <li><label title="Include HTML from cells in output">Include HTML: <input class="output-html" type="checkbox" /></label></li>
<li><label title="Wrap all values in quotes">Wrap in Quotes: <input class="output-wrap" type="checkbox" /></label></li> <li><label title="Wrap all values in quotes">Wrap in Quotes: <input class="output-wrap" type="checkbox" /></label></li>
<li><label title="Include both header rows in output">Include both header rows: <input class="output-headers" type="checkbox" checked /></label></li>
<li><label title="Choose a download filename">Filename: <input class="output-filename" type="text" size="15" value="mytable.csv"/></label></li> <li><label title="Choose a download filename">Filename: <input class="output-filename" type="text" size="15" value="mytable.csv"/></label></li>
</ul> </ul>
</div> </div>

View File

@ -26,7 +26,7 @@
replaceTab : '\x09', replaceTab : '\x09',
popupTitle : 'Output', popupTitle : 'Output',
popupStyle : 'width:100%;height:100%;', // for textarea popupStyle : 'width:100%;height:100%;margin:0;resize:none;', // for textarea
message : 'Your device does not support downloading. Please try again in desktop browser.', message : 'Your device does not support downloading. Please try again in desktop browser.',
init : function(c) { init : function(c) {
@ -183,9 +183,13 @@
// requires JSON stringify; if it doesn't exist, the output will show [object Object],... in the output window // requires JSON stringify; if it doesn't exist, the output will show [object Object],... in the output window
mydata = hasStringify ? JSON.stringify(tmpData) : tmpData; mydata = hasStringify ? JSON.stringify(tmpData) : tmpData;
} else { } else {
if (wo.output_includeHeader) {
tmp = [ headers[ ( len > 1 && wo.output_headerRows ) ? indx % len : len - 1 ] ]; tmp = [ headers[ ( len > 1 && wo.output_headerRows ) ? indx % len : len - 1 ] ];
tmpData = output.row2CSV(wo, wo.output_headerRows ? headers : tmp, outputArray) tmpData = output.row2CSV(wo, wo.output_headerRows ? headers : tmp, outputArray)
.concat( output.row2CSV(wo, csvData, outputArray) ); .concat( output.row2CSV(wo, csvData, outputArray) );
} else {
tmpData = output.row2CSV(wo, csvData, outputArray);
}
// stringify the array; if stringify doesn't exist the array will be flattened // stringify the array; if stringify doesn't exist the array will be flattened
mydata = outputArray && hasStringify ? JSON.stringify(tmpData) : tmpData.join('\n'); mydata = outputArray && hasStringify ? JSON.stringify(tmpData) : tmpData.join('\n');
@ -369,8 +373,9 @@
output_ignoreColumns : [], // columns to ignore [0, 1,... ] (zero-based index) output_ignoreColumns : [], // columns to ignore [0, 1,... ] (zero-based index)
output_hiddenColumns : false, // include hidden columns in the output output_hiddenColumns : false, // include hidden columns in the output
output_includeFooter : false, // include footer rows in the output output_includeFooter : false, // include footer rows in the output
output_includeHeader : true, // include header rows in the output
output_headerRows : false, // if true, include multiple header rows
output_dataAttrib : 'data-name', // header attrib containing modified header name output_dataAttrib : 'data-name', // header attrib containing modified header name
output_headerRows : false, // if true, include multiple header rows (JSON only)
output_delivery : 'popup', // popup, download output_delivery : 'popup', // popup, download
output_saveRows : 'filtered', // (a)ll, (v)isible, (f)iltered or jQuery filter selector output_saveRows : 'filtered', // (a)ll, (v)isible, (f)iltered or jQuery filter selector
output_duplicateSpans : true, // duplicate output data in tbody colspan/rowspan output_duplicateSpans : true, // duplicate output data in tbody colspan/rowspan
@ -390,14 +395,12 @@
output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + (cellIndex) + ')'; }, output_callbackJSON : function($cell, txt, cellIndex) { return txt + '(' + (cellIndex) + ')'; },
// the need to modify this for Excel no longer exists // the need to modify this for Excel no longer exists
output_encoding : 'data:application/octet-stream;charset=utf8,', output_encoding : 'data:application/octet-stream;charset=utf8,',
/* override internal save file code and use an external plugin such as // override internal save file code and use an external plugin such as
* https://github.com/eligrey/FileSaver.js (example) // https://github.com/eligrey/FileSaver.js
* output_savePlugin: function(config, widgetOptions, data) { output_savePlugin : null /* function(c, wo, data) {
* var blob = new Blob([data], {type: wo.output_encoding}); var blob = new Blob([data], {type: wo.output_encoding});
* saveAs(blob, wo.output_saveFileName); saveAs(blob, wo.output_saveFileName);
* } } */
*/
output_savePlugin : null
}, },
init: function(table, thisWidget, c) { init: function(table, thisWidget, c) {
output.init(c); output.init(c);