Debian Codegraph @

docs/example-widget-print.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Print Widget</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
12 <script src="js/jquery-ui.min.js"></script>
13 <link rel="stylesheet" href="css/jq.css">
14 <link href="css/prettify.css" rel="stylesheet">
15 <script src="js/prettify.js"></script>
16 <script src="js/docs.js"></script>
17
18 <!-- Tablesorter: required -->
19 <link rel="stylesheet" href="../css/theme.blue.css">
20 <script src="../js/jquery.tablesorter.js"></script>
21 <script src="../js/jquery.tablesorter.widgets.js"></script>
22
23 <script src="../js/widgets/widget-columnSelector.js"></script>
24 <script src="../js/widgets/widget-print.js"></script>
25
26 <style>
27 .options th.narrow {
28 width: 150px;
29 }
30 .button {
31 position: relative;
32 padding: 1px 6px;
33 display: inline-block;
34 cursor: pointer;
35 border: #000 1px solid;
36 border-radius: 5px;
37 }
38 .columnSelector, .hidden {
39 display: none;
40 }
41 #colSelect1:checked + label {
42 color: #307ac5;
43 }
44 #colSelect1:checked ~ #columnSelector {
45 display: block;
46 }
47 .columnSelector {
48 width: 120px;
49 position: absolute;
50 top: 30px;
51 padding: 10px;
52 background: #fff;
53 border: #99bfe6 1px solid;
54 border-radius: 5px;
55 }
56 .columnSelector label {
57 display: block;
58 text-align: left;
59 }
60 .columnSelector label:nth-child(1) {
61 border-bottom: #99bfe6 solid 1px;
62 margin-bottom: 5px;
63 }
64 .columnSelector input {
65 margin-right: 5px;
66 }
67 .columnSelector .disabled {
68 color: #ddd;
69 }
70 </style>
71
72 <script id="js">$(function() {
73
74 // v2.24.6, change popup print & close button text
75 // See print_now description
76 $.tablesorter.language.button_print = "Print";
77 $.tablesorter.language.button_close = "Close";
78
79 $(".tablesorter").tablesorter({
80 theme: 'blue',
81 widgets: ["zebra", "filter", "print", "columnSelector"],
82 widgetOptions : {
83 columnSelector_container : $('#columnSelector'),
84 columnSelector_name : 'data-name',
85
86 print_title : '', // this option > caption > table id > "table"
87 print_dataAttrib : 'data-name', // header attrib containing modified header name
88 print_rows : 'f', // (a)ll, (v)isible, (f)iltered, or custom css selector
89 print_columns : 's', // (a)ll, (v)isible or (s)elected (columnSelector widget)
90 print_extraCSS : '', // add any extra css definitions for the popup window here
91 print_styleSheet : '../css/theme.blue.css', // add the url of your print stylesheet
92 print_now : true, // Open the print dialog immediately if true
93 // callback executed when processing completes - default setting is null
94 print_callback : function(config, $table, printStyle) {
95 // do something to the $table (jQuery object of table wrapped in a div)
96 // or add to the printStyle string, then...
97 // print the table using the following code
98 $.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
99 }
100 }
101 });
102
103 $('.print').click(function() {
104 $('.tablesorter').trigger('printTable');
105 });
106
107 });</script>
108
109 </head>
110 <body>
111 <div id="banner">
112 <h1>table<em>sorter</em></h1>
113 <h2>Print Widget</h2>
114 <h3>Flexible client-side table sorting</h3>
115 <a href="index.html">Back to documentation</a>
116 </div>
117 <div id="main">
118
119 <p></p>
120 <br>
121
122 <div id="root" class="accordion">
123
124 <h3><a href="#">Notes</a></h3>
125 <div>
126 <ul>
127 <li>In <span class="version">v2.24.6</span>, added <code>print_now</code> option.</li>
128 <li>In <span class="version updated">v2.24.1</span>, the <code>print_rows</code> option will allow using a custom css selector.</li>
129 <li>In <span class="version">v2.17.2</span>, the print popup window now closes with the dialog window &amp; jQuery version requirement was changed from v1.7+ to v1.2+.</li>
130 <li>
131 In <span class="version">v2.17.0</span>, added the <code>print_callback</code> option.<br>
132 <br>
133 </li>
134 <li>This widget will <strong>only work</strong> in tablesorter version 2.8+ and jQuery version <del>1.7+</del> 1.2.6+ (<span class="version updated">v2.17.2</span>; but filter &amp; columnSelector widgets still require jQuery 1.7+).</li>
135 <li>The user can print all, visible or filtered rows. And, choose to print all or selected columns (using the columnSelector widget).</li>
136 <li>By default, the widget is set to only print filtered rows &amp; visible columns.</li>
137 </ul>
138 </div>
139
140 <h3><a href="#">Options</a></h3>
141 <div>
142 <h3>Print widget default options (added inside of tablesorter <code>widgetOptions</code>)</h3>
143 <div class="tip">
144 <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.
145 </div>
146 <table class="tablesorter-blue options">
147 <thead>
148 <tr><th class="narrow">Option</th><th class="narrow">Default</th><th>Description</th></tr>
149 </thead>
150 <tbody>
151
152 <tr id="print_title">
153 <td><a href="#" class="permalink">print_title</a></td>
154 <td><code>''</code></td>
155 <td>
156 This option sets the title of the popup window & ends up being printed at the top of each page.
157 <div class="collapsible">
158 <br>
159 If this option is blank, the print title is obtained from the table caption, then the table id, then just "table", in that order.
160 </div>
161 </td>
162 </tr>
163
164 <tr id="print_dataattrib">
165 <td><a href="#" class="permalink">print_dataAttrib</a></td>
166 <td><code>'data-name'</code></td>
167 <td>
168 This option contains the data-attribute name which contains the modified table header content.
169 <div class="collapsible">
170 <br>
171 In this demo, the column selector widget is set up to also use the "data-name" attribute so the column selector popup and print header will display this alternate text.<pre class="prettyprint lang-html">&lt;th data-name="First"&gt;First Name&lt;/th&gt;</pre>
172 </div>
173 </td>
174 </tr>
175
176 <tr id="print_rows">
177 <td><a href="#" class="permalink">print_rows</a></td>
178 <td><code>'filtered'</code></td>
179 <td>
180 Set this option to designate which rows are printed (<span class="version updated">v2.24.1</span>).
181 <div class="collapsible">
182 <br>
183 This option has three settings (only the first letter is necessary):
184 <ul>
185 <li><code>'all'</code> or <code>'a'</code> - always print all rows (this will not work if the pager has `removeRows` set to `true`).</li>
186 <li><code>'filtered'</code> or <code>'f'</code> - only filtered rows are printed (even if the pager is applied).</li>
187 <li><code>'visible'</code> or <code>'v'</code> - only visible rows are printed (the current pager page).</li>
188 <li>css selector - include a css selector to apply to a row (<span class="version">v2.24.1</span>).
189 <ul>
190 <li>For example, <code>'.checked'</code>, <code>'[data-region~="west"]</code>, <code>':nth-child(2n)'</code></li>
191 <li>For reference, internally, this option is added immediately after (no space) a <code>'tr'</code> css selector.</li>
192 <li>For this option to be used as a css selector, a check of the following characters at the start of the string is done:
193 <ul>
194 <li><code>'.'</code> (class selector)</li>
195 <li><code>'#'</code> (id selector)</li>
196 <li><code>':'</code> (pseudo selector)</li>
197 <li><code>'['</code> (start of an attribute selector)</li>
198 </ul>
199 </li>
200 </ul>
201 </li>
202 </ul>
203 <span class="label label-info">Note</span> only rows contained within the table are printed; i.e. if ajax is being used to populate the table, only the currently loaded rows will print.
204 </div>
205 </td>
206 </tr>
207
208 <tr id="print_columns">
209 <td><a href="#" class="permalink">print_columns</a></td>
210 <td><code>'selected'</code></td>
211 <td>
212 Set this option to designate which columns are printed.
213 <div class="collapsible">
214 <br>
215 This option has three settings (only the first letter is necessary):
216 <ul>
217 <li><code>'all'</code> or <code>'a'</code> - always print all columns; including any intentionally hidden table cells.</li>
218 <li><code>'selected'</code> or <code>'s'</code> - only selected (visible) columns are printed (as set by the columnSelector widget).</li>
219 <li><code>'visible'</code> or <code>'v'</code> - set this option to print the table columns as is... no extra css is added to force table cells to be visible.</li>
220 </ul>
221 </div>
222 </td>
223 </tr>
224
225 <tr id="print_extracss">
226 <td><a href="#" class="permalink">print_extraCSS</a></td>
227 <td><code>''</code></td>
228 <td>
229 If you have any custom css to add to the print popup window, include it in this option
230 <div class="collapsible">
231 <br>
232 Use this option as follows:
233 <pre class="prettyprint lang-js">print_extraCSS : ".caption { display: none; }"</pre>
234 </div>
235 </td>
236 </tr>
237
238 <tr id="print_stylesheet">
239 <td><a href="#" class="permalink">print_styleSheet</a></td>
240 <td><code>''</code></td>
241 <td>
242 If you have stylesheet you want to add to the print popup window, include the url in this option
243 <div class="collapsible">
244 <br>
245 Use this option as follows:
246 <pre class="prettyprint lang-js">print_styleSheet : "../css/theme.blue.css"</pre>
247 </div>
248 </td>
249 </tr>
250
251 <tr id="print_now">
252 <td><a href="#" class="permalink">print_now</a></td>
253 <td><code>true</code></td>
254 <td>
255 If <code>true</code>, the browser print dialog will open immediately (<span class="version">v2.24.6</span>).
256 <div class="collapsible">
257 <br>
258 If <code>false</code>, the popup window will open with two additional controls:
259 <ul>
260 <li>A "Print" button - open the print dialog inside of the popup window.</li>
261 <li>A "Close" button - close the popup window.</li>
262 </ul>
263 To change the text of the buttons, use the following settings:
264 <pre class="prettyprint lang-js">$.tablesorter.language.button_print = "Imprimer";
265 $.tablesorter.language.button_close = "Ferme";</pre>
266 The above code can be added before or after initializing tablesorter. It doesn't matter because the values are only accessed when the user initiates a print.
267 </div>
268 </td>
269 </tr>
270
271 <tr id="print_callback">
272 <td><a href="#" class="permalink">print_callback</a></td>
273 <td><code>null</code></td>
274 <td>
275 This callback allows further processing of the table & style (<span class="version">v2.17.0</span>)
276 <div class="collapsible">
277 <br>
278 When this callback is executed, three parameters are provided:
279 <ul>
280 <li><code>config</code> - The table config settings.</li>
281 <li><code>$table</code> - The table wrapped in a div, as a jQuery object. It contains all the rows &amp; 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>
282 <li><code>printStyle</code> - This is the print style associated with the table. It contains styles to show or hide selected rows &amp; columns, including the columnSelector style to hide specific columns.</li>
283 </ul>
284 When any processing within this callback is complete, you must manually call the print function to continue printing as follows:
285 <pre class="prettyprint lang-js">// print callback example
286 print_callback : function( config, $table, printStyle ) {
287 // do something to the table or printStyle string
288 // use the following code to continue printing
289 $.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
290 }</pre>
291 </div>
292 </td>
293 </tr>
294
295 </tbody>
296 </table>
297 </div>
298
299 <h3><a href="#">Method</a></h3>
300 <div>
301 <ul>
302 <li>To make the print widget work programmatically, trigger a "printTable" event.
303 <pre class="prettyprint lang-js">$('.print').click(function() {
304 $('.tablesorter').trigger('printTable');
305 });</pre>
306 </li>
307 </ul>
308 </div>
309
310 </div>
311
312 <p></p>
313
314 <h1>Demo</h1>
315 <div id="demo"><div class="print button">Print</div>
316
317 <div class="columnSelectorWrapper button">
318 <input id="colSelect1" type="checkbox" class="hidden">
319 <label class="columnSelectorButton" for="colSelect1">Column</label>
320 <div id="columnSelector" class="columnSelector">
321 <!-- this div is where the column selector is added -->
322 </div>
323 </div>
324 <table class="tablesorter">
325 <thead>
326 <tr>
327 <th class="filter-select" data-placeholder="Select a name" data-priority="2" data-name="First">First Name</th>
328 <th data-placeholder="Exact matches only" data-priority="critical">Last Name</th>
329 <th data-placeholder="Choose a city" data-priority="4">City</th>
330 <th data-placeholder="Enter an age" data-priority="3">Age</th>
331 <th data-placeholder="Select a filter">Total</th>
332 <th class="filter-select">Discount</th>
333 <th>Date</th>
334 </tr>
335 </thead>
336 <tbody>
337 <tr><td>Aaron</td><td>Johnson Sr</td><td>Atlanta</td><td>35</td><td>$5.95</td><td>22%</td><td>Jun 26, 2004 7:22 AM</td></tr>
338 <tr><td>Aaron</td><td>Johnson</td><td>Yuma</td><td>12</td><td>$2.99</td><td>5%</td><td>Aug 21, 2009 12:21 PM</td></tr>
339 <tr><td>Clark</td><td>Henry Jr</td><td>Tampa</td><td>51</td><td>$42.29</td><td>18%</td><td>Oct 13, 2000 1:15 PM</td></tr>
340 <tr><td>Denni</td><td>Henry</td><td>New York</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>
341 <tr><td>John</td><td>Hood</td><td>Boston</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
342 <tr><td>Clark</td><td>Kent Sr</td><td>Los Angeles</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
343 <tr><td>Peter</td><td>Kent Esq</td><td>Seattle</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2021 9:12 AM</td></tr>
344 <tr><td>Peter</td><td>Johns</td><td>Milwaukee</td><td>13</td><td>$5.29</td><td>4%</td><td>Jan 8, 2012 5:11 PM</td></tr>
345 <tr><td>Aaron</td><td>Evan</td><td>Chicago</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2004 11:23 AM</td></tr>
346 <tr><td>Bruce</td><td>Evans</td><td>Upland</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>
347 <tr><td>Clark</td><td>McMasters</td><td>Pheonix</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2010 7:23 PM</td></tr>
348 <tr><td>Dennis</td><td>Masters</td><td>Indianapolis</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2001 1:12 PM</td></tr>
349 <tr><td>John</td><td>Hood</td><td>Fort Worth</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2011 10:55 AM</td></tr>
350 </tbody>
351 </table></div>
352
353 <h1>Javascript</h1>
354 <div id="javascript">
355 <pre class="prettyprint lang-javascript"></pre>
356 </div>
357
358 <h1>HTML</h1>
359 <div id="html">
360 <pre class="prettyprint lang-html"></pre>
361 </div>
362
363 </div>
364
365 </body>
366 </html>