mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Docs: added basic setup example for the output widget
This commit is contained in:
parent
298c2f10ad
commit
03ab6d638b
@ -235,6 +235,38 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3><a href="#">Basic Setup</a></h3>
|
||||||
|
<div>
|
||||||
|
Using the default settings of this widget will:
|
||||||
|
<ul>
|
||||||
|
<li>Output csv to a popup window.</li>
|
||||||
|
<li>Only include the last header row (if there are more than one rows).</li>
|
||||||
|
<li>Only include filtered rows (all rows will be included, even if the filter widget isn't being used).</li>
|
||||||
|
<li>Will only output the table cell text (ignoring any HTML).</li>
|
||||||
|
</ul>
|
||||||
|
Of course, all of the above behavior can be modified using the options.<br>
|
||||||
|
This is an example of how to setup a table using only the default settings:
|
||||||
|
<h4>HTML</h4>
|
||||||
|
<pre class="prettyprint lang-html"><button class="download">Get CSV</button>
|
||||||
|
<table class="tablesorter">
|
||||||
|
<!-- .... -->
|
||||||
|
</table></pre>
|
||||||
|
<h4>Script</h4>
|
||||||
|
<pre class="prettyprint lang-js">$(function () {
|
||||||
|
var $table = $('table');
|
||||||
|
|
||||||
|
$('.download').click(function(){
|
||||||
|
// tell the output widget do it's thing
|
||||||
|
$table.trigger('outputTable');
|
||||||
|
});
|
||||||
|
|
||||||
|
$table.tablesorter({
|
||||||
|
theme: 'blue',
|
||||||
|
widgets: ['zebra', 'output']
|
||||||
|
});
|
||||||
|
});</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3><a href="#">Rowspan and colspan</a></h3>
|
<h3><a href="#">Rowspan and colspan</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
@ -246,7 +278,8 @@
|
|||||||
will produce an output like this:
|
will produce an output like this:
|
||||||
<pre class="prettyprint lang-js">data, values, values</pre>
|
<pre class="prettyprint lang-js">data, values, values</pre>
|
||||||
</li>
|
</li>
|
||||||
<li><span class="label label-info">Important</span> But, if a JSON output is chosen, the resulting object for a row cannot contain duplicate keys.
|
<li><span class="label label-info">Important</span> But, if a JSON output is chosen, the resulting object for a row cannot contain duplicate keys.<br>
|
||||||
|
<br>
|
||||||
<pre class="prettyprint lang-js">[{ "data" : "0", "values" : "1", "values" : "2" }]
|
<pre class="prettyprint lang-js">[{ "data" : "0", "values" : "1", "values" : "2" }]
|
||||||
// becomes [{ "data" : "0", "values" : "2" }]</pre>
|
// becomes [{ "data" : "0", "values" : "2" }]</pre>
|
||||||
So, in order to fix this, any key (header name) with a colspan will have the column index added to the end (see the <code>output_callbackJSON</code> option). So the same HTML above will produce the following output:
|
So, in order to fix this, any key (header name) with a colspan will have the column index added to the end (see the <code>output_callbackJSON</code> option). So the same HTML above will produce the following output:
|
||||||
@ -267,13 +300,15 @@
|
|||||||
<th>value2</th>
|
<th>value2</th>
|
||||||
<th>value3</th>
|
<th>value3</th>
|
||||||
</tr></pre>
|
</tr></pre>
|
||||||
And the <code>output_headerRows</code> is <code>true</code>, the output will appear look like this:
|
And the <code>output_headerRows</code> is <code>true</code>, the output will look like this:
|
||||||
<pre class="prettyprint lang-js">line,values,values,values
|
<pre class="prettyprint lang-js">line,values,values,values
|
||||||
line,value1,value2,value3
|
line,value1,value2,value3
|
||||||
1,1.1,1.2,1.3
|
1,1.1,1.2,1.3
|
||||||
1,1.4,1.5,1.5</pre>
|
1,1.4,1.5,1.5</pre>
|
||||||
</li>
|
</li>
|
||||||
<li><span class="label label-info">Important</span> But, if a JSON output is chosen, and <code>output_headerRows</code> is set to <code>false</code>, only header names from the last row will be applied to the output. The HTML above will produce this output:
|
<li>
|
||||||
|
<span class="label label-info">Important</span> But, if a JSON output is chosen, and <code>output_headerRows</code> is set to <code>false</code>, only header names from the last row will be applied to the output. The HTML above will produce this output:<br>
|
||||||
|
<br>
|
||||||
<pre class="prettyprint lang-js">[
|
<pre class="prettyprint lang-js">[
|
||||||
{ "line" : "1", "value1" : "1.1", "value2" : "1.2", "value3" : "1.3" },
|
{ "line" : "1", "value1" : "1.1", "value2" : "1.2", "value3" : "1.3" },
|
||||||
{ "line" : "1", "value1" : "1.4", "value2" : "1.5", "value3" : "1.5" }
|
{ "line" : "1", "value1" : "1.4", "value2" : "1.5", "value3" : "1.5" }
|
||||||
@ -292,10 +327,11 @@ line,value1,value2,value3
|
|||||||
|
|
||||||
<h3><a href="#">Options</a></h3>
|
<h3><a href="#">Options</a></h3>
|
||||||
<div>
|
<div>
|
||||||
<h3>Output widget default options (added inside of tablesorter <code>widgetOptions</code>)</h3>
|
<h4>Output widget default options (added inside of tablesorter <code>widgetOptions</code>)</h4>
|
||||||
<div class="tip">
|
<div class="tip">
|
||||||
<span class="label label-info">TIP!</span> Click on the link in the option column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location.
|
<span class="label label-info">TIP!</span> Click on the link in the option column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location.
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
<table id="output-options" class="tablesorter-bootstrap options">
|
<table id="output-options" class="tablesorter-bootstrap options">
|
||||||
<colgroup><col style="width:135px"><col style="width:100px"></colgroup>
|
<colgroup><col style="width:135px"><col style="width:100px"></colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
@ -321,7 +357,7 @@ line,value1,value2,value3
|
|||||||
[ "Rank", "First", "Last", "Age", "Total", "Discount", "Date" ],
|
[ "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" ],
|
||||||
[ "166", "Bruce Lee", "Evans", "22", "$13.19", "11%", "Jan 18, 2007 9:12 AM" ],
|
[ "166", "Bruce Lee", "Evans", "22", "$13.19", "11%", "Jan 18, 2007 9:12 AM" ],
|
||||||
]</pre><span class="label label-info">Note</span> this requires <code>JSON.stringify</code>, or the result will be a flattened array.<br>
|
]</pre><span class="label label-info">Note</span> this requires <a href="http://caniuse.com/#feat=json"><code>JSON.stringify</code></a>, or the result will be a flattened array.<br>
|
||||||
<br>
|
<br>
|
||||||
And when this option is set to <code>"json"</code>, the resulting output will be a valid JSON format:<br>
|
And when this option is set to <code>"json"</code>, the resulting output will be a valid JSON format:<br>
|
||||||
<pre class="prettyprint lang-js">[
|
<pre class="prettyprint lang-js">[
|
||||||
@ -342,7 +378,7 @@ line,value1,value2,value3
|
|||||||
"Discount": "11%",
|
"Discount": "11%",
|
||||||
"Date": "Jan 18, 2007 9:12 AM"
|
"Date": "Jan 18, 2007 9:12 AM"
|
||||||
}
|
}
|
||||||
]</pre><span class="label label-info">Note</span> this also requires <code>JSON.stringify</code>, or the result will show <code>[ [object Object], ... ]</code> in the output.
|
]</pre><span class="label label-info">Note</span> this also requires <a href="http://caniuse.com/#feat=json"><code>JSON.stringify</code></a>, or the result will show <code>[ [object Object], ... ]</code> in the output.
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user