mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
363 lines
16 KiB
HTML
363 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>jQuery plugin: Tablesorter 2.0 - Resizable Columns Widget</title>
|
|
|
|
<!-- jQuery -->
|
|
<script src="js/jquery-1.4.4.min.js"></script>
|
|
|
|
<!-- Demo stuff -->
|
|
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
|
|
<script src="js/jquery-ui.min.js"></script>
|
|
<link rel="stylesheet" href="css/jq.css">
|
|
<link href="css/prettify.css" rel="stylesheet">
|
|
<script src="js/prettify.js"></script>
|
|
<script src="js/docs.js"></script>
|
|
|
|
<!-- Tablesorter: required -->
|
|
<link rel="stylesheet" href="../css/theme.blue.css">
|
|
<script src="../js/jquery.tablesorter.js"></script>
|
|
<script src="../js/widgets/widget-resizable.js"></script>
|
|
<script src="../js/widgets/widget-storage.js"></script>
|
|
|
|
<style id="css">th.tablesorter-header.resizable-false {
|
|
background-color: #e6bf99;
|
|
}
|
|
/* ensure box-sizing is set to content-box, if using jQuery versions older than 1.8;
|
|
this page is using jQuery 1.4 */
|
|
*, *:before, *:after {
|
|
-moz-box-sizing: content-box;
|
|
-webkit-box-sizing: content-box;
|
|
box-sizing: content-box;
|
|
}
|
|
/* overflow table */
|
|
.wrapper {
|
|
overflow-x: auto;
|
|
overflow-y: hidden;
|
|
width: 450px;
|
|
}
|
|
.wrapper table {
|
|
width: auto;
|
|
table-layout: fixed;
|
|
}
|
|
.wrapper .tablesorter td {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
min-width: 10px;
|
|
}
|
|
.wrapper .tablesorter th {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
min-width: 10px;
|
|
}</style>
|
|
|
|
<script id="js">$(function() {
|
|
|
|
$('.narrow-table').tablesorter({
|
|
theme : 'blue',
|
|
// initialize zebra striping and resizable widgets on the table
|
|
widgets: [ 'zebra', 'resizable', 'stickyHeaders' ],
|
|
widgetOptions: {
|
|
storage_useSessionStorage : true,
|
|
resizable_addLastColumn : true
|
|
}
|
|
});
|
|
|
|
// overflow table
|
|
$('.wrapper table').tablesorter({
|
|
theme: 'blue',
|
|
widgets: ['zebra', 'resizable'],
|
|
widgetOptions: {
|
|
resizable_addLastColumn : true,
|
|
resizable_widths : [ '100px', '60px', '30px', '50px', '60px', '140px' ]
|
|
}
|
|
});
|
|
|
|
$('.full-width-table').tablesorter({
|
|
theme : 'blue',
|
|
// initialize zebra striping and resizable widgets on the table
|
|
widgets: [ 'zebra', 'resizable', 'stickyHeaders' ],
|
|
widgetOptions: {
|
|
resizable: true,
|
|
// These are the default column widths which are used when the table is
|
|
// initialized or resizing is reset; note that the "Age" column is not
|
|
// resizable, but the width can still be set to 40px here
|
|
resizable_widths : [ '10%', '10%', '40px', '10%', '100px' ]
|
|
}
|
|
});
|
|
|
|
});</script>
|
|
</head>
|
|
<body>
|
|
<div id="banner">
|
|
<h1>table<em>sorter</em></h1>
|
|
<h2>Resizable Columns Widget</h2>
|
|
<h3>Flexible client-side table sorting</h3>
|
|
<a href="index.html">Back to documentation</a>
|
|
</div>
|
|
<div id="main">
|
|
|
|
<p></p>
|
|
<br>
|
|
<div id="root" class="accordion">
|
|
|
|
<h3><a href="#">Notes</a></h3>
|
|
<div>
|
|
<ul>
|
|
<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>
|
|
<li><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>&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>).</li>
|
|
<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).<br><br></li>
|
|
|
|
<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>
|
|
<li>In <span class="version">v2.21.5</span>, this widget now works with the columnSelector widget & tables with margins (see <a href="https://github.com/Mottie/tablesorter/issues/864">issue #864</a>).</li>
|
|
<li>In <span class="version">v2.21.3</span>
|
|
<ul>
|
|
<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>
|
|
<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>
|
|
</ul>
|
|
</li>
|
|
<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>
|
|
<li>In <span class="version">v2.15.12</span>, added <code>resizable_widths</code> option which allows the setting of default & reset header widths.</li>
|
|
<li>As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.</li>
|
|
<li>This widget now saves all changed column widths to local storage, or it falls back to a cookie! (v2.1)</li>
|
|
<li>Column width saving requires the new "$.tablesorter.storage()" function included with the "jquery.tablesorter.widgets.js" file (v2.1).</li>
|
|
<li>Right clicking (opening the context menu) will now reset the resized columns (v2.4).</li>
|
|
<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>
|
|
<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):
|
|
<ul>
|
|
<li>jQuery data <code>data-resizable="false"</code>.</li>
|
|
<li>metadata <code>class="{ resizable: 'false'}"</code>. This requires the metadata plugin.</li>
|
|
<li>headers option <code>headers : { 0 : { resizable : 'false' } }</code>.</li>
|
|
<li>header class name <code>class="resizable-false"</code>.</li>
|
|
</ul>
|
|
</li>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
</ul>
|
|
</div>
|
|
|
|
<h3><a href="#">Options</a></h3>
|
|
<div>
|
|
<h4>Resizable widget defaults (added inside of tablesorter <code>widgetOptions</code>)</h4>
|
|
<div>
|
|
<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.
|
|
</div>
|
|
<table class="options tablesorter-blue" data-sortlist="[[0,0]]">
|
|
<thead>
|
|
<tr><th>Option</th><th class="defaults">Default</th><th class="sorter-false">Description</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
|
|
<tr id="resizable">
|
|
<td><a href="#" class="permalink">resizable</a></td>
|
|
<td>true</td>
|
|
<td>When <code>true</code> and the storage widget is included, all column widths will be saved to storage.
|
|
<div class="collapsible">
|
|
<p>This means that when the page is reloaded, any adjusted column widths will be restored.</p>
|
|
<p>The adjusted column sizes can be reset at any time by right-clicking on the table header.</p>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr id="resizable-add-last-column">
|
|
<td><a href="#" class="permalink">resizable_addLastColumn</a></td>
|
|
<td>false</td>
|
|
<td>When <code>true</code>, the last column of the table is made resizable.
|
|
<div class="collapsible">
|
|
<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>
|
|
<p>On narrower tables, the table width will be adjusted.</p>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr id="resizable-widths">
|
|
<td><a href="#" class="permalink">resizable_widths</a></td>
|
|
<td>[ ]</td>
|
|
<td>Set any default column widths within this zero-based-column-indexed array
|
|
<div class="collapsible">
|
|
<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).</p>
|
|
<p>The array may contain any css allowed width definitions (e.g. percentage, pixels, em, etc).</p>
|
|
<p>Undefined column widths to not add a specified width to the column</p>
|
|
<p>Here is an example from the second table in this demo showing how to set this option:</p>
|
|
<pre class="prettyprint lang-js">// Note that the "Age" column is not resizable,
|
|
// but the width can still be set to 40px here
|
|
resizable_widths : [ '10%', '10%', '40px', '10%', '100px' ]</pre>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr id="resizable-throttle">
|
|
<td><a href="#" class="permalink">resizable_throttle</a></td>
|
|
<td>false</td>
|
|
<td>When this option is set to a number, or true, the resizing event from the window is throttled.
|
|
<div class="collapsible">
|
|
<p>Essentially, throttling the resize event limits the number of times the javascript is executed while resizing the window.</p>
|
|
<p>Without any throttling, slower browsers may lag while the javascript adjusts the column widths of the table.</p>
|
|
<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>
|
|
<p>When this option is set to <code>true</code>, a default of <code>5</code> (milliseconds) is used.</p>
|
|
<p>If setting a number, try to keep this number in the <code>0</code> to <code>10</code> range.</p>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr id="resizable-target-last">
|
|
<td><a href="#" class="permalink">resizable_targetLast</a></td>
|
|
<td>false</td>
|
|
<td>When <code>true</code>, the last column will be targeted for resizing.
|
|
<div class="collapsible">
|
|
<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>
|
|
<p>When <code>false</code>, resizing a column will move the column border between it's neighbors.</p>
|
|
<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>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<h1>Demo</h1>
|
|
<div id="demo">
|
|
<h3>
|
|
Non-full width table
|
|
<sup class="results">†</sup>
|
|
<small>(individual columns resize)</small>
|
|
</h3>
|
|
<table class="narrow-table" style="width:auto">
|
|
<thead>
|
|
<tr>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th class="resizable-false">Age</th>
|
|
<th>Total</th>
|
|
<th>Discount</th>
|
|
<th>Date</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
</tbody>
|
|
</table>
|
|
<small><span class="results">†</span> Resized values for this table are saved to <em>session storage</em> - values are lost once the browser is closed.</small>
|
|
|
|
<br>
|
|
|
|
<h3>
|
|
Overflow table
|
|
<sup class="results">‡</sup>
|
|
<small>(<code>text-overflow: ellipsis</code> set)</small>
|
|
</h3>
|
|
<div class="wrapper">
|
|
<table class="tablesorter">
|
|
<thead>
|
|
<tr>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th class="resizable-false">Age</th>
|
|
<th>Total</th>
|
|
<th>Discount</th>
|
|
<th>Date</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<h3>
|
|
Full width table
|
|
<sup class="results">‡</sup>
|
|
<small>(use shift to force last column to resize)</small>
|
|
</h3>
|
|
<table class="full-width-table">
|
|
<thead>
|
|
<tr>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th class="resizable-false">Age</th>
|
|
<th>Total</th>
|
|
<th>Discount</th>
|
|
<th>Date</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
</tbody>
|
|
</table>
|
|
<small><span class="results">‡</span> Resized values for this table are saved to <em>local storage</em> - values are not lost once the browser is closed.</small>
|
|
</div>
|
|
<p></p>
|
|
|
|
<h1>Page Header</h1>
|
|
<div>
|
|
<pre class="prettyprint lang-html"><!-- blue theme stylesheet with additional css styles added in v2.0.17 -->
|
|
<link rel="stylesheet" href="../css/theme.blue.css">
|
|
<!-- tablesorter plugin -->
|
|
<script src="../js/jquery.tablesorter.js"></script>
|
|
|
|
<!-- tablesorter widget file - loaded after the plugin -->
|
|
<script src="../js/jquery.tablesorter.widgets.js"></script></pre>
|
|
</div>
|
|
|
|
<h1>CSS</h1>
|
|
<div id="css">
|
|
<pre class="prettyprint lang-css"></pre>
|
|
</div>
|
|
|
|
<h1>Javascript</h1>
|
|
<div id="javascript">
|
|
<pre class="prettyprint lang-javascript"></pre>
|
|
</div>
|
|
|
|
<h1>HTML</h1>
|
|
<div>
|
|
<pre class="prettyprint lang-html"><!-- The Age column is set to not be resizable -->
|
|
<table class="tablesorter" style="width:auto">
|
|
<thead>
|
|
<tr>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th class="resizable-false">Age</th>
|
|
<th>Total</th>
|
|
<th>Discount</th>
|
|
<th>Date</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
...
|
|
</tbody>
|
|
</table></pre>
|
|
</div>
|
|
|
|
<div class="next-up">
|
|
<hr />
|
|
Next up: <a href="example-widget-savesort.html">Applying the save sort widget ››</a>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|
|
|