Output: add duplicate spans option. Fixes #619

This commit is contained in:
Mottie 2014-05-20 21:40:57 -05:00
parent 063f109659
commit c429a0aa0a
2 changed files with 65 additions and 36 deletions

View File

@ -117,13 +117,13 @@
widgetOptions : { widgetOptions : {
filter_filteredRow : 'filtered', filter_filteredRow : 'filtered',
filter_reset : demos[groupIndex] + ' .reset', filter_reset : demos[groupIndex] + ' .reset',
output_separator : ',', // ',' 'json', 'array' or separator (e.g. ',') output_separator : ',', // ',' 'json', 'array' or separator (e.g. ',')
output_ignoreColumns: [], // columns to ignore [0, 1,... ] (zero-based index) output_ignoreColumns : [], // columns to ignore [0, 1,... ] (zero-based index)
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_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, (f)iltered or (v)isible output_saveRows : 'f', // (a)ll, (f)iltered or (v)isible
output_duplicateSpans: true, // duplicate output data in tbody colspan/rowspan
output_replaceQuote : '\u201c;', // change quote to left double quote output_replaceQuote : '\u201c;', // change quote to left double quote
output_includeHTML : true, // output includes all cell HTML (except the header cells) output_includeHTML : true, // output includes all cell HTML (except the header cells)
output_trimSpaces : false, // remove extra white-space characters from beginning & end output_trimSpaces : false, // remove extra white-space characters from beginning & end
@ -224,7 +224,12 @@
<h3><a href="#">Notes</a></h3> <h3><a href="#">Notes</a></h3>
<div> <div>
<ul> <ul>
<li>In <span class="version">v2.16.5</span>, added the <code>output_ignoreColumns</code> option &amp; modified the <code>output_callback</code> parameters.</li> <li>In <span class="version">v2.16.5</span>,
<ul>
<li>Added the <code>output_ignoreColumns</code> option &amp; modified the <code>output_callback</code> parameters.</li>
<li>Added <code>output_duplicateSpans</code> option to duplicate (when <code>true</code>) colspan &amp; rowspan content across cells.</li>
</ul>
</li>
<li>In <span class="version">v2.16.4</span>, added the <code>output_encoding</code> option.<br><br></li> <li>In <span class="version">v2.16.4</span>, added the <code>output_encoding</code> option.<br><br></li>
<li>This widget will <strong>only work</strong> in tablesorter version 2.8+ and jQuery version 1.7+.</li> <li>This widget will <strong>only work</strong> in tablesorter version 2.8+ and jQuery version 1.7+.</li>
<li>This widget can output the table data to: <li>This widget can output the table data to:
@ -477,6 +482,28 @@ line,value1,value2,value3
</div> </div>
</td> </td>
</tr> </tr>
<tr id="output_duplicatespans">
<td><a href="#" class="permalink">output_duplicateSpans</a></td>
<td><code>true</code></td>
<td>
When <code>true</code>, colspan &amp; rowspan content is duplicated in the output
<div class="collapsible">
<br>
By default, any <em>tbody</em> cells that are included in the colspan or rowspan will have the cell's content duplicated in the output. When set to <code>false</code>, the cells within the colspan or rowspan will be empty.<br>
Here is an example of the second table output with this option set to <code>false</code>:
<pre class="prettyprint lang-js">line,values,values,values
line,value1,value2,value3
1,1.1,1.2,1.3
,1.4,1.5,
2,2.1,2.2,2.3
,2.4,2.5,
3,3.1,3.2,3.3
,3.4,3.5,
4,4.1,,4.2
,,,4.3</pre>This option does not affect thead cells, they will always have duplicated content.
</div>
</td>
</tr>
<tr id="output_replacequote"> <tr id="output_replacequote">
<td><a href="#" class="permalink">output_replaceQuote</a></td> <td><a href="#" class="permalink">output_replaceQuote</a></td>
<td><code>'\u201c;'</code></td> <td><code>'\u201c;'</code></td>

View File

@ -42,6 +42,7 @@ output = ts.output = {
var $this, row, col, rowlen, collen, txt, var $this, row, col, rowlen, collen, txt,
wo = c.widgetOptions, wo = c.widgetOptions,
tmpRow = [], tmpRow = [],
dupe = wo.output_duplicateSpans,
addSpanIndex = isHeader && isJSON && wo.output_headerRows && $.isFunction(wo.output_callbackJSON), addSpanIndex = isHeader && isJSON && wo.output_headerRows && $.isFunction(wo.output_callbackJSON),
cellIndex = 0; cellIndex = 0;
$rows.each(function(rowIndex) { $rows.each(function(rowIndex) {
@ -55,7 +56,7 @@ output = ts.output = {
txt = output.formatData( wo, $this.attr(wo.output_dataAttrib) || $this.html(), isHeader ); txt = output.formatData( wo, $this.attr(wo.output_dataAttrib) || $this.html(), isHeader );
for (row = 1; row <= rowlen; row++) { for (row = 1; row <= rowlen; row++) {
if (!tmpRow[rowIndex + row]) { tmpRow[rowIndex + row] = []; } if (!tmpRow[rowIndex + row]) { tmpRow[rowIndex + row] = []; }
tmpRow[rowIndex + row][cellIndex] = txt; tmpRow[rowIndex + row][cellIndex] = isHeader ? txt : dupe ? txt : '';
} }
} }
// process colspans // process colspans
@ -69,11 +70,11 @@ output = ts.output = {
for (row = 0; row < rowlen; row++) { for (row = 0; row < rowlen; row++) {
if (!tmpRow[rowIndex + row]) { tmpRow[rowIndex + row] = []; } if (!tmpRow[rowIndex + row]) { tmpRow[rowIndex + row] = []; }
tmpRow[rowIndex + row][cellIndex + col] = addSpanIndex ? tmpRow[rowIndex + row][cellIndex + col] = addSpanIndex ?
wo.output_callbackJSON($this, txt, cellIndex + col) || txt + '(' + (cellIndex + col) + ')' : txt; wo.output_callbackJSON($this, txt, cellIndex + col) || txt + '(' + (cellIndex + col) + ')' : isHeader ? txt : dupe ? txt : '';
} }
} else { } else {
tmpRow[rowIndex][cellIndex + col] = addSpanIndex ? tmpRow[rowIndex][cellIndex + col] = addSpanIndex ?
wo.output_callbackJSON($this, txt, cellIndex + col) || txt + '(' + (cellIndex + col) + ')' : txt; wo.output_callbackJSON($this, txt, cellIndex + col) || txt + '(' + (cellIndex + col) + ')' : isHeader ? txt : dupe ? txt : '';
} }
} }
} }
@ -81,7 +82,7 @@ output = ts.output = {
// don't include hidden columns // don't include hidden columns
if ( $this.css('display') !== 'none' ) { if ( $this.css('display') !== 'none' ) {
// skip column if already defined // skip column if already defined
while (tmpRow[rowIndex][cellIndex]) { cellIndex++; } while (typeof tmpRow[rowIndex][cellIndex] !== 'undefined') { cellIndex++; }
tmpRow[rowIndex][cellIndex] = tmpRow[rowIndex][cellIndex] || tmpRow[rowIndex][cellIndex] = tmpRow[rowIndex][cellIndex] ||
output.formatData( wo, $this.attr(wo.output_dataAttrib) || $this.html(), isHeader ); output.formatData( wo, $this.attr(wo.output_dataAttrib) || $this.html(), isHeader );
cellIndex++; cellIndex++;
@ -259,11 +260,12 @@ ts.addWidget({
id: "output", id: "output",
options: { options: {
output_separator : ',', // set to "json", "array" or any separator output_separator : ',', // set to "json", "array" or any separator
output_ignoreColumns: [], // columns to ignore [0, 1,... ] (zero-based index) output_ignoreColumns : [], // columns to ignore [0, 1,... ] (zero-based index)
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_headerRows : false, // if true, include multiple header rows (JSON only)
output_delivery : 'popup', // popup, download output_delivery : 'popup', // popup, download
output_saveRows : 'filtered', // all, visible or filtered output_saveRows : 'filtered', // all, visible or filtered
output_duplicateSpans: true, // duplicate output data in tbody colspan/rowspan
output_replaceQuote : '\u201c;', // left double quote output_replaceQuote : '\u201c;', // left double quote
output_includeHTML : false, output_includeHTML : false,
output_trimSpaces : true, output_trimSpaces : true,