435 lines
19 KiB
HTML
435 lines
19 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>jQuery tablesorter 2.0 - Resizable Columns Widget</title>
|
|
|
|
<!-- jQuery -->
|
|
<script src="js/jquery-latest.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>
|
|
|
|
<style>
|
|
/* test resizable handle positioning
|
|
.tablesorter-resizable-handle {
|
|
background: rgba(255, 0, 0, .4)
|
|
}
|
|
*/
|
|
</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, deprecated in v2.28.8
|
|
storage_storageType: 's', // use first letter (s)ession
|
|
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 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>
|
|
<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>&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>
|
|
|
|
<li>In <span class="version">v2.29.0</span>, added a <a class="intlink" href="#resizablecomplete"><code>resizableComplete</code></a> event.</li>
|
|
<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>
|
|
<li>In <span class="version">v2.28.5</span>,
|
|
<ul>
|
|
<li>A <a class="intlink" href="#events"><code>resizableUpdate</code></a> event can be triggered on the table to update the resizable handles.</li>
|
|
<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>
|
|
</ul>
|
|
</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-include-footer">
|
|
<td><a href="#" class="permalink">resizable_includeFooter</a></td>
|
|
<td>true</td>
|
|
<td>When <code>true</code>, the resizable handle will extend into the table footer (<span class="version">v2.28.8</span>).
|
|
<div class="collapsible">
|
|
<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>
|
|
<p>If <code>false</code>, the resizable handle will not extend into the table footer.</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) or triggering a <a class="intlink" href="#events"><code>resizableReset</code></a> event on the table.</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>
|
|
|
|
<h3><a href="#">Methods</a></h3>
|
|
<div>
|
|
<h3>resizableUpdate</h3>
|
|
<blockquote>
|
|
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.
|
|
<pre class="prettyprint lang-js">// equivalent to $( window ).trigger( 'resize' );
|
|
$( 'table' ).trigger( 'resizableUpdate' );</pre>
|
|
</blockquote>
|
|
|
|
<h3>resizableReset</h3>
|
|
<blockquote>
|
|
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.
|
|
<pre class="prettyprint lang-js">$( 'table' ).trigger( 'resizableReset' );</pre>
|
|
</blockquote>
|
|
</div>
|
|
|
|
<h3><a href="#">Events</a></h3>
|
|
<div>
|
|
<h3>resizableComplete</h3>
|
|
<blockquote>
|
|
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
|
|
<pre class="prettyprint lang-js">$( 'table' ).on( 'resizableComplete', function(event) {
|
|
var resizable_vars = this.config.widgetOptions.resizable_vars;
|
|
var saved = {
|
|
// resizable_vars.storedSizes is an empty array when no resizing was done
|
|
// otherwise it contains each column width (padding & border width not included) in pixels
|
|
columnWidths: resizable_vars.storedSizes,
|
|
// overall table width
|
|
tableWidth: resizable_vars.tableWidth
|
|
};
|
|
// do something with the values
|
|
});</pre>
|
|
</blockquote>
|
|
</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>
|
|
<tfoot>
|
|
<tr>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Age</th>
|
|
<th>Total</th>
|
|
<th>Discount</th>
|
|
<th>Date</th>
|
|
</tr>
|
|
</tfoot>
|
|
<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>
|