Debian Codegraph @

docs/example-widget-resizable.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Resizable Columns 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/widgets/widget-resizable.js"></script>
22 <script src="../js/widgets/widget-storage.js"></script>
23
24 <style id="css">th.tablesorter-header.resizable-false {
25 background-color: #e6bf99;
26 }
27 /* ensure box-sizing is set to content-box, if using jQuery versions older than 1.8;
28 this page is using jQuery 1.4 */
29 *, *:before, *:after {
30 -moz-box-sizing: content-box;
31 -webkit-box-sizing: content-box;
32 box-sizing: content-box;
33 }
34 /* overflow table */
35 .wrapper {
36 overflow-x: auto;
37 overflow-y: hidden;
38 width: 450px;
39 }
40 .wrapper table {
41 width: auto;
42 table-layout: fixed;
43 }
44 .wrapper .tablesorter td {
45 overflow: hidden;
46 text-overflow: ellipsis;
47 white-space: nowrap;
48 min-width: 10px;
49 }
50 .wrapper .tablesorter th {
51 overflow: hidden;
52 text-overflow: ellipsis;
53 min-width: 10px;
54 }</style>
55
56 <style>
57 /* test resizable handle positioning
58 .tablesorter-resizable-handle {
59 background: rgba(255, 0, 0, .4)
60 }
61 */
62 </style>
63
64 <script id="js">$(function() {
65
66 $('.narrow-table').tablesorter({
67 theme : 'blue',
68 // initialize zebra striping and resizable widgets on the table
69 widgets: [ 'zebra', 'resizable', 'stickyHeaders' ],
70 widgetOptions: {
71 // storage_useSessionStorage : true, deprecated in v2.28.8
72 storage_storageType: 's', // use first letter (s)ession
73 resizable_addLastColumn : true
74 }
75 });
76
77 // overflow table
78 $('.wrapper table').tablesorter({
79 theme: 'blue',
80 widgets: ['zebra', 'resizable'],
81 widgetOptions: {
82 resizable_addLastColumn : true,
83 resizable_widths : [ '100px', '60px', '30px', '50px', '60px', '140px' ]
84 }
85 });
86
87 $('.full-width-table').tablesorter({
88 theme : 'blue',
89 // initialize zebra striping and resizable widgets on the table
90 widgets: [ 'zebra', 'resizable', 'stickyHeaders' ],
91 widgetOptions: {
92 resizable: true,
93 // These are the default column widths which are used when the table is
94 // initialized or resizing is reset; note that the "Age" column is not
95 // resizable, but the width can still be set to 40px here
96 resizable_widths : [ '10%', '10%', '40px', '10%', '100px' ]
97 }
98 });
99
100 });</script>
101 </head>
102 <body>
103 <div id="banner">
104 <h1>table<em>sorter</em></h1>
105 <h2>Resizable Columns Widget</h2>
106 <h3>Flexible client-side table sorting</h3>
107 <a href="index.html">Back to documentation</a>
108 </div>
109 <div id="main">
110
111 <p></p>
112 <br>
113 <div id="root" class="accordion">
114
115 <h3><a href="#">Notes</a></h3>
116 <div>
117 <ul>
118 <li><span class="label label-info">IMPORTANT</span> If using jQuery versions older than 1.8, css box-sizing for the table <em>MUST</em> be set as <code>box-sizing: content-box;</code> or the resizable widget will not work properly.</li>
119 <li><span class="label label-info">IMPORTANT</span> The resizable will not work properly if the <a href="index.html#widthfixed"><code>widthFixed</code></a> option is set to <code>true</code>. Make sure it is set to <code>false</code> (default setting).</li>
120 <li><del><span class="label label-info">IMPORTANT</span> The resize div ends up with a zero height if the header cell is empty. Please include at least a <code>&amp;nbsp;</code> in the cell to allow it to render properly (<a href="https://github.com/Mottie/tablesorter/issues/844" title="Thanks gigib82!">ref</a>)</del>. No longer necessary as the resizable widget no longer adds elements inside the table header cells.<br><br></li>
121
122 <li>In <span class="version">v2.29.0</span>, added a <a class="intlink" href="#resizablecomplete"><code>resizableComplete</code></a> event.</li>
123 <li>In <span class="version">v2.28.8</span>, added the <a class="intlink" href="#resizable-include-footer"><code>resizable_includeFooter</code></a> option.</li>
124 <li>In <span class="version">v2.28.5</span>,
125 <ul>
126 <li>A <a class="intlink" href="#events"><code>resizableUpdate</code></a> event can be triggered on the table to update the resizable handles.</li>
127 <li>A <a class="intlink" href="#events"><code>resizableReset</code></a> event can be triggered to reset the resizable columns to their default widths.</li>
128 </ul>
129 </li>
130 <li>In <span class="version">v2.22.2</span>, resizable will now work with tables inside an overflow wrapper (see <a href="https://github.com/Mottie/tablesorter/issues/953">issue #953</a>).</li>
131 <li>In <span class="version">v2.21.5</span>, this widget now works with the columnSelector widget &amp; tables with margins (see <a href="https://github.com/Mottie/tablesorter/issues/864">issue #864</a>).</li>
132 <li>In <span class="version">v2.21.3</span>
133 <ul>
134 <li>Performed a major overhaul on the resizable widget to add resizable handles outside of the table, so now the resizable handles can be used over the entire height of the table!</li>
135 <li>This change allows the resizable widget to work seemlessly with the <strong>stickyHeaders</strong> widget (included in this demo); sadly, to make it work with the scroller widget will require more work.</li>
136 </ul>
137 </li>
138 <li>In <span class="version">v2.17.4</span>, modified the bindings so the mouse move will now work on the document instead of only within the table header; this makes interaction consistent with what the user expects.</li>
139 <li>In <span class="version">v2.15.12</span>, added <code>resizable_widths</code> option which allows the setting of default &amp; reset header widths.</li>
140 <li>As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.</li>
141 <li>This widget now saves all changed column widths to local storage, or it falls back to a cookie! (v2.1)</li>
142 <li>Column width saving requires the new "$.tablesorter.storage()" function included with the "jquery.tablesorter.widgets.js" file (v2.1).</li>
143 <li>Right clicking (opening the context menu) will now reset the resized columns (v2.4).</li>
144 <li>Holding down the shift key while resizing will force the last column or the table to resize instead of the next column, but only if the table is full width (v2.7.4).</li>
145 <li>Prevent resizing a column by adding any of the following (they all do the same thing), set in order of priority (v2.7.4):
146 <ul>
147 <li>jQuery data <code>data-resizable="false"</code>.</li>
148 <li>metadata <code>class="{ resizable: 'false'}"</code>. This requires the metadata plugin.</li>
149 <li>headers option <code>headers : { 0 : { resizable : 'false' } }</code>.</li>
150 <li>header class name <code>class="resizable-false"</code>.</li>
151 </ul>
152 </li>
153 <li>Setting the <code>resizable</code> widget option to <code>false</code>, will only prevent the saving of resized columns, it has nothing to do with preventing a column from being resized.</li>
154 <li>Because this widget uses jQuery's <code>closest()</code> (jQuery 1.3+) and <code>index()</code> (jQuery 1.4+) functions, it requires these newer versions of jQuery in order to work.</li>
155 <li>In order to save the resized widths, jQuery version 1.4.1+ should be used because jQuery's <code>parseJson()</code> function is needed.</li>
156 <li>Setting the <code>resizable_addLastColumn</code> widget option to <code>true</code> will add the resizable handle to the last column, see the "non-full" width table below (<span class="version">v2.9.0</span>).</li>
157 </ul>
158 </div>
159
160 <h3><a href="#">Options</a></h3>
161 <div>
162 <h4>Resizable widget defaults (added inside of tablesorter <code>widgetOptions</code>)</h4>
163 <div>
164 <span class="label label-info">TIP!</span> Click on the link in the function 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.
165 </div>
166 <table class="options tablesorter-blue" data-sortlist="[[0,0]]">
167 <thead>
168 <tr><th>Option</th><th class="defaults">Default</th><th class="sorter-false">Description</th></tr>
169 </thead>
170 <tbody>
171
172 <tr id="resizable">
173 <td><a href="#" class="permalink">resizable</a></td>
174 <td>true</td>
175 <td>When <code>true</code> and the storage widget is included, all column widths will be saved to storage.
176 <div class="collapsible">
177 <p>This means that when the page is reloaded, any adjusted column widths will be restored.</p>
178 <p>The adjusted column sizes can be reset at any time by right-clicking on the table header.</p>
179 </div>
180 </td>
181 </tr>
182
183 <tr id="resizable-add-last-column">
184 <td><a href="#" class="permalink">resizable_addLastColumn</a></td>
185 <td>false</td>
186 <td>When <code>true</code>, the last column of the table is made resizable.
187 <div class="collapsible">
188 <p>If the table is full width, adjusting the right edge would actually shrink or stretch <em>all</em> columns without moving the right border.</p>
189 <p>On narrower tables, the table width will be adjusted.</p>
190 </div>
191 </td>
192 </tr>
193
194 <tr id="resizable-include-footer">
195 <td><a href="#" class="permalink">resizable_includeFooter</a></td>
196 <td>true</td>
197 <td>When <code>true</code>, the resizable handle will extend into the table footer (<span class="version">v2.28.8</span>).
198 <div class="collapsible">
199 <p>When <code>true</code>, this option includes the entire height of the table footer. If the table does not include a footer, the resize handle will stop at the last row.</p>
200 <p>If <code>false</code>, the resizable handle will not extend into the table footer.</p>
201 </div>
202 </td>
203 </tr>
204
205 <tr id="resizable-widths">
206 <td><a href="#" class="permalink">resizable_widths</a></td>
207 <td>[ ]</td>
208 <td>Set any default column widths within this zero-based-column-indexed array
209 <div class="collapsible">
210 <p>This option allows the setting of column widths initially (before any resizing occurs, or if there are no saved column widths) and when resetting (right-click on the column header) or triggering a <a class="intlink" href="#events"><code>resizableReset</code></a> event on the table.</p>
211 <p>The array may contain any css allowed width definitions (e.g. percentage, pixels, em, etc).</p>
212 <p>Undefined column widths to not add a specified width to the column</p>
213 <p>Here is an example from the second table in this demo showing how to set this option:</p>
214 <pre class="prettyprint lang-js">// Note that the "Age" column is not resizable,
215 // but the width can still be set to 40px here
216 resizable_widths : [ '10%', '10%', '40px', '10%', '100px' ]</pre>
217 </div>
218 </td>
219 </tr>
220
221 <tr id="resizable-throttle">
222 <td><a href="#" class="permalink">resizable_throttle</a></td>
223 <td>false</td>
224 <td>When this option is set to a number, or true, the resizing event from the window is throttled.
225 <div class="collapsible">
226 <p>Essentially, throttling the resize event limits the number of times the javascript is executed while resizing the window.</p>
227 <p>Without any throttling, slower browsers may lag while the javascript adjusts the column widths of the table.</p>
228 <p>With excessive throttling, the user will notice the table column width lag (while will be seen as the width jumping sporatically to catch up to the mouse) behind the mouse movement.</p>
229 <p>When this option is set to <code>true</code>, a default of <code>5</code> (milliseconds) is used.</p>
230 <p>If setting a number, try to keep this number in the <code>0</code> to <code>10</code> range.</p>
231 </div>
232 </td>
233 </tr>
234
235 <tr id="resizable-target-last">
236 <td><a href="#" class="permalink">resizable_targetLast</a></td>
237 <td>false</td>
238 <td>When <code>true</code>, the last column will be targeted for resizing.
239 <div class="collapsible">
240 <p>When <code>true</code>, resizing a column will change the size of the selected column, and the last column, not the selected column's neighbor.</p>
241 <p>When <code>false</code>, resizing a column will move the column border between it's neighbors.</p>
242 <p>Also, in a <em>full width table</em>, if this option is <code>false</code>, the same behavior as when this option is <code>true</code> can be seen when resizing a column while holding down the <kbd>Shift</kbd> key on the keyboard - the last column is resized.</p>
243 </div>
244 </td>
245 </tr>
246
247 </tbody>
248 </table>
249 </div>
250
251 <h3><a href="#">Methods</a></h3>
252 <div>
253 <h3>resizableUpdate</h3>
254 <blockquote>
255 A <code>resizableUpdate</code> event (added <span class="version">v2.28.5</span>) can be triggered on the table to force an update of the resizable handles. This behaves the same as triggering a <code>resize</code> event on the <code>window</code> without causing any unwanted page reflow.
256 <pre class="prettyprint lang-js">// equivalent to $( window ).trigger( 'resize' );
257 $( 'table' ).trigger( 'resizableUpdate' );</pre>
258 </blockquote>
259
260 <h3>resizableReset</h3>
261 <blockquote>
262 A <code>resizableReset</code> event (added <span class="version">v2.28.5</span>) can be triggered on the table reset the resizable columns to their original, or set <a class="intlink" href="#resizable-widths"><code>resizable_widths</code></a> value. This is the same as the user right-clicking on the table header causing a reset.
263 <pre class="prettyprint lang-js">$( 'table' ).trigger( 'resizableReset' );</pre>
264 </blockquote>
265 </div>
266
267 <h3><a href="#">Events</a></h3>
268 <div>
269 <h3>resizableComplete</h3>
270 <blockquote>
271 A <code>resizableComplete</code> event (added <span class="version">v2.29.0</span>) is triggered on the table after the user has resized a column and
272 <pre class="prettyprint lang-js">$( 'table' ).on( 'resizableComplete', function(event) {
273 var resizable_vars = this.config.widgetOptions.resizable_vars;
274 var saved = {
275 // resizable_vars.storedSizes is an empty array when no resizing was done
276 // otherwise it contains each column width (padding &amp; border width not included) in pixels
277 columnWidths: resizable_vars.storedSizes,
278 // overall table width
279 tableWidth: resizable_vars.tableWidth
280 };
281 // do something with the values
282 });</pre>
283 </blockquote>
284 </div>
285
286 </div>
287
288 <h1>Demo</h1>
289 <div id="demo">
290 <h3>
291 Non-full width table
292 <sup class="results">&dagger;</sup>
293 <small>(individual columns resize)</small>
294 </h3>
295 <table class="narrow-table" style="width:auto">
296 <thead>
297 <tr>
298 <th>First Name</th>
299 <th>Last Name</th>
300 <th class="resizable-false">Age</th>
301 <th>Total</th>
302 <th>Discount</th>
303 <th>Date</th>
304 </tr>
305 </thead>
306 <tfoot>
307 <tr>
308 <th>First Name</th>
309 <th>Last Name</th>
310 <th>Age</th>
311 <th>Total</th>
312 <th>Discount</th>
313 <th>Date</th>
314 </tr>
315 </tfoot>
316 <tbody>
317 <tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>
318 <tr><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
319 <tr><td>Clark</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
320 <tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>
321 <tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>
322 </tbody>
323 </table>
324 <small><span class="results">&dagger;</span> Resized values for this table are saved to <em>session storage</em> - values are lost once the browser is closed.</small>
325
326 <br>
327
328 <h3>
329 Overflow table
330 <sup class="results">&Dagger;</sup>
331 <small>(<code>text-overflow: ellipsis</code> set)</small>
332 </h3>
333 <div class="wrapper">
334 <table class="tablesorter">
335 <thead>
336 <tr>
337 <th>First Name</th>
338 <th>Last Name</th>
339 <th class="resizable-false">Age</th>
340 <th>Total</th>
341 <th>Discount</th>
342 <th>Date</th>
343 </tr>
344 </thead>
345 <tbody>
346 <tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>
347 <tr><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
348 <tr><td>Clark</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
349 <tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>
350 <tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>
351 </tbody>
352 </table>
353 </div>
354
355 <br>
356
357 <h3>
358 Full width table
359 <sup class="results">&Dagger;</sup>
360 <small>(use shift to force last column to resize)</small>
361 </h3>
362 <table class="full-width-table">
363 <thead>
364 <tr>
365 <th>First Name</th>
366 <th>Last Name</th>
367 <th class="resizable-false">Age</th>
368 <th>Total</th>
369 <th>Discount</th>
370 <th>Date</th>
371 </tr>
372 </thead>
373 <tbody>
374 <tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>
375 <tr><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>
376 <tr><td>Clark</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>
377 <tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>
378 <tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>
379 </tbody>
380 </table>
381 <small><span class="results">&Dagger;</span> Resized values for this table are saved to <em>local storage</em> - values are not lost once the browser is closed.</small>
382 </div>
383 <p></p>
384
385 <h1>Page Header</h1>
386 <div>
387 <pre class="prettyprint lang-html">&lt;!-- blue theme stylesheet with additional css styles added in v2.0.17 --&gt;
388 &lt;link rel=&quot;stylesheet&quot; href=&quot;../css/theme.blue.css&quot;&gt;
389 &lt;!-- tablesorter plugin --&gt;
390 &lt;script src=&quot;../js/jquery.tablesorter.js&quot;&gt;&lt;/script&gt;
391
392 &lt;!-- tablesorter widget file - loaded after the plugin --&gt;
393 &lt;script src=&quot;../js/jquery.tablesorter.widgets.js&quot;&gt;&lt;/script&gt;</pre>
394 </div>
395
396 <h1>CSS</h1>
397 <div id="css">
398 <pre class="prettyprint lang-css"></pre>
399 </div>
400
401 <h1>Javascript</h1>
402 <div id="javascript">
403 <pre class="prettyprint lang-javascript"></pre>
404 </div>
405
406 <h1>HTML</h1>
407 <div>
408 <pre class="prettyprint lang-html">&lt;!-- The Age column is set to not be resizable --&gt;
409 &lt;table class=&quot;tablesorter&quot; style=&quot;width:auto&quot;&gt;
410 &lt;thead&gt;
411 &lt;tr&gt;
412 &lt;th&gt;First Name&lt;/th&gt;
413 &lt;th&gt;Last Name&lt;/th&gt;
414 &lt;th class=&quot;resizable-false&quot;&gt;Age&lt;/th&gt;
415 &lt;th&gt;Total&lt;/th&gt;
416 &lt;th&gt;Discount&lt;/th&gt;
417 &lt;th&gt;Date&lt;/th&gt;
418 &lt;/tr&gt;
419 &lt;/thead&gt;
420 &lt;tbody&gt;
421 ...
422 &lt;/tbody&gt;
423 &lt;/table&gt;</pre>
424 </div>
425
426 <div class="next-up">
427 <hr />
428 Next up: <a href="example-widget-savesort.html">Applying the save sort widget &rsaquo;&rsaquo;</a>
429 </div>
430
431 </div>
432
433 </body>
434 </html>