mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Print: add print_callback option
This commit is contained in:
parent
e9b9b1bf0f
commit
346587f4bc
@ -80,7 +80,14 @@
|
||||
print_rows : 'f', // (a)ll, (v)isible or (f)iltered
|
||||
print_columns : 's', // (a)ll, (s)elected (columnSelector widget), or empty string
|
||||
print_extraCSS : '', // add any extra css definitions for the popup window here
|
||||
print_styleSheet : '../css/theme.blue.css' // add the url of your print stylesheet
|
||||
print_styleSheet : '../css/theme.blue.css', // add the url of your print stylesheet
|
||||
// callback executed when processing completes - default setting is null
|
||||
print_callback : function(config, $table, printStyle){
|
||||
// do something to the $table (jQuery object of table wrapped in a div)
|
||||
// or add to the printStyle string, then...
|
||||
// print the table using the following code
|
||||
$.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -108,6 +115,10 @@
|
||||
<h3><a href="#">Notes</a></h3>
|
||||
<div>
|
||||
<ul>
|
||||
<li>
|
||||
In <span class="version">v2.16.5</span>, added the <code>print_callback</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>The user can print all, visible or filtered rows. And, choose to print all or selected columns (using the columnSelector widget).</li>
|
||||
<li>By default, the widget is set to only print filtered rows & visible columns.</li>
|
||||
@ -211,6 +222,30 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="print_callback">
|
||||
<td><a href="#" class="permalink">print_callback</a></td>
|
||||
<td><code>null</code></td>
|
||||
<td>
|
||||
This callback allows further processing of the table & style (<span class="version">v2.16.5</span>)
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
When this callback is executed, three parameters are provided:
|
||||
<ul>
|
||||
<li><code>config</code> - The table config settings.</li>
|
||||
<li><code>$table</code> - The table wrapped in a div, as a jQuery object. It contains all the rows & cells of the original table, but the content of cells will be replaced by the contents of the associated <code>data-name</code> attribute.</li>
|
||||
<li><code>printStyle</code> - This is the print style associated with the table. It contains styles to show or hide selected rows & columns, including the columnSelector style to hide specific columns.</li>
|
||||
</ul>
|
||||
When any processing within this callback is complete, you must manually call the print function to continue printing as follows:
|
||||
<pre class="prettyprint lang-js">// print callback example
|
||||
print_callback : function( config, $table, printStyle ) {
|
||||
// do something to the table or printStyle string
|
||||
// use the following code to continue printing
|
||||
$.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
|
||||
}</pre>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -498,7 +498,7 @@
|
||||
<br>
|
||||
</li>
|
||||
|
||||
<li><span class="label label-info">Beta</span> <a href="example-widget-print.html">Print widget</a> (<span class="version">v2.16.4</span>)</li>
|
||||
<li><span class="label label-info">Beta</span> <a href="example-widget-print.html">Print widget</a> (<span class="version">v2.16.4</span>; <span class="version updated">v2.16.5</span>)</li>
|
||||
<li><span class="label label-info">Beta</span> <a href="example-widget-reflow.html">Reflow widget</a> (<span class="version">v2.16</span>)</li>
|
||||
<li><a href="example-widgets.html">Repeat Headers widget</a> (v2.0.5; <span class="version updated">v2.9</span>)</li>
|
||||
<li><span class="results">†</span> <a href="example-widget-resizable.html">Resizable Columns widget</a> (v2.0.23.1; <span class="version updated">v2.15.12</span>)</li>
|
||||
|
@ -63,12 +63,18 @@ printTable = ts.printTable = {
|
||||
|
||||
printStyle += wo.print_extraCSS;
|
||||
|
||||
printTable.printOutput(c, wo, printStyle, $table.html());
|
||||
// callback function
|
||||
if ( $.isFunction(wo.print_callback) ) {
|
||||
wo.print_callback( c, $table, printStyle );
|
||||
} else {
|
||||
printTable.printOutput(c, $table.html(), printStyle);
|
||||
}
|
||||
|
||||
}, // end process
|
||||
|
||||
printOutput : function(c, wo, style, data) {
|
||||
var generator = window.open('', wo.print_title, 'width=500,height=300'),
|
||||
printOutput : function(c, data, style) {
|
||||
var wo = c.widgetOptions,
|
||||
generator = window.open('', wo.print_title, 'width=500,height=300'),
|
||||
t = wo.print_title || c.$table.find('caption').text() || c.$table[0].id || document.title || 'table';
|
||||
generator.document.write(
|
||||
'<html><head><title>' + t + '</title>' +
|
||||
@ -95,7 +101,14 @@ ts.addWidget({
|
||||
print_rows : 'filtered', // (a)ll, (v)isible or (f)iltered
|
||||
print_columns : 'selected', // (a)ll or (s)elected (if columnSelector widget is added)
|
||||
print_extraCSS : '', // add any extra css definitions for the popup window here
|
||||
print_styleSheet : '' // add the url of your print stylesheet
|
||||
print_styleSheet : '', // add the url of your print stylesheet
|
||||
// callback executed when processing completes
|
||||
// to continue printing, use the following function:
|
||||
// function( config, $table, printStyle ) {
|
||||
// // do something to the table or printStyle string
|
||||
// $.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
|
||||
// }
|
||||
print_callback : null
|
||||
},
|
||||
init: function(table, thisWidget, c) {
|
||||
printTable.init(c);
|
||||
|
Loading…
Reference in New Issue
Block a user