StickyHeaders: add appendTo option

This commit is contained in:
Rob Garrison 2016-07-26 02:46:32 -05:00
parent 710929579e
commit 2a249b4ebd
No known key found for this signature in database
GPG Key ID: 0A42D160D71978E1
3 changed files with 42 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -2048,7 +2048,11 @@ $(function(){
// row // row
stickyHeaders: '', stickyHeaders: '',
// jQuery selector or object to attach sticky header to // jQuery selector or object to append sticky headers to
stickyHeaders_appendTo: null,
// jQuery selector or object to attach sticky headers scroll listener to
// overridden by xScroll & yScroll settings
stickyHeaders_attachTo: null, stickyHeaders_attachTo: null,
// jQuery selector or object to monitor horizontal scroll position // jQuery selector or object to monitor horizontal scroll position
@ -3575,9 +3579,33 @@ $('table').trigger('search', false);</pre></div>
<td><a href="example-widget-sticky-header.html">Example</a></td> <td><a href="example-widget-sticky-header.html">Example</a></td>
</tr> </tr>
<tr id="widget-sticky-headers-appendto">
<td><a href="#" class="permalink">stickyHeaders_appendTo</a></td>
<td>String, jQuery Object</td>
<td>null</td>
<td>
Sticky Headers widget: jQuery selector or object to physically attach the sticky headers (<span class="version">v2.27.0</span>).
<div class="collapsible">
<p>
<span class="label label-warning">Note</span> Appending the sticky headers to an element that does not have the same dimensions (width) as the table wrapper will produce a sticky header that does not match the table size!
</p>
Use the <a href="#widget-sticky-headers-appendto"><code>stickyHeaders_appendTo</code></a> option as follows:<br>
<pre class="prettyprint lang-js">$(function(){
$("table").tablesorter({
widgets: ["stickyHeaders"],
widgetOptions : {
// Where to attach the stickyHeaders
stickyHeaders_appendTo : '.wrapper' // $('.wrapper') jQuery object can also be used
}
});
});</pre></div>
</td>
<td></td>
</tr>
<tr id="widget-sticky-headers-attachto"> <tr id="widget-sticky-headers-attachto">
<td><a href="#" class="permalink">stickyHeaders_attachTo</a></td> <td><a href="#" class="permalink">stickyHeaders_attachTo</a></td>
<td>String</td> <td>String, jQuery Object</td>
<td>null</td> <td>null</td>
<td> <td>
Sticky Headers widget: points to the table wrapper to stick the headers to while scrolling. Use this option to point to their needs (<span class="version">v2.14.4</span>). Sticky Headers widget: points to the table wrapper to stick the headers to while scrolling. Use this option to point to their needs (<span class="version">v2.14.4</span>).
@ -3599,7 +3627,7 @@ $('table').trigger('search', false);</pre></div>
<tr id="widget-sticky-headers-xscroll"> <tr id="widget-sticky-headers-xscroll">
<td><a href="#" class="permalink">stickyHeaders_xScroll</a></td> <td><a href="#" class="permalink">stickyHeaders_xScroll</a></td>
<td>String</td> <td>String, jQuery Object</td>
<td>null</td> <td>null</td>
<td> <td>
Sticky Headers widget: points to the element in which to monitor for horizontal scrolling (<span class="version">v2.18.0</span>). Sticky Headers widget: points to the element in which to monitor for horizontal scrolling (<span class="version">v2.18.0</span>).
@ -3623,7 +3651,7 @@ $('table').trigger('search', false);</pre></div>
<tr id="widget-sticky-headers-yscroll"> <tr id="widget-sticky-headers-yscroll">
<td><a href="#" class="permalink">stickyHeaders_yScroll</a></td> <td><a href="#" class="permalink">stickyHeaders_yScroll</a></td>
<td>String</td> <td>String, jQuery Object</td>
<td>null</td> <td>null</td>
<td> <td>
Sticky Headers widget: points to the element in which to monitor for vertical scrolling (<span class="version">v2.18.0</span>). Sticky Headers widget: points to the element in which to monitor for vertical scrolling (<span class="version">v2.18.0</span>).

View File

@ -61,10 +61,11 @@
// ************************** // **************************
ts.addWidget({ ts.addWidget({
id: 'stickyHeaders', id: 'stickyHeaders',
priority: 60, // sticky widget must be initialized after the filter widget! priority: 55, // sticky widget must be initialized after the filter widget!
options: { options: {
stickyHeaders : '', // extra class name added to the sticky header row stickyHeaders : '', // extra class name added to the sticky header row
stickyHeaders_attachTo : null, // jQuery selector or object to attach sticky header to stickyHeaders_appendTo : null, // jQuery selector or object to phycially attach the sticky headers
stickyHeaders_attachTo : null, // jQuery selector or object to attach scroll listener to (overridden by xScroll & yScroll settings)
stickyHeaders_xScroll : null, // jQuery selector or object to monitor horizontal scroll position (defaults: xScroll > attachTo > window) stickyHeaders_xScroll : null, // jQuery selector or object to monitor horizontal scroll position (defaults: xScroll > attachTo > window)
stickyHeaders_yScroll : null, // jQuery selector or object to monitor vertical scroll position (defaults: yScroll > attachTo > window) stickyHeaders_yScroll : null, // jQuery selector or object to monitor vertical scroll position (defaults: yScroll > attachTo > window)
stickyHeaders_offset : 0, // number or jquery selector targeting the position:fixed element stickyHeaders_offset : 0, // number or jquery selector targeting the position:fixed element
@ -215,8 +216,12 @@
ts.bindEvents(table, $stickyThead.children().children('.' + ts.css.header)); ts.bindEvents(table, $stickyThead.children().children('.' + ts.css.header));
if (wo.stickyHeaders_appendTo) {
$(wo.stickyHeaders_appendTo).append( $stickyWrap );
} else {
// add stickyheaders AFTER the table. If the table is selected by ID, the original one (first) will be returned. // add stickyheaders AFTER the table. If the table is selected by ID, the original one (first) will be returned.
$table.after( $stickyWrap ); $table.after( $stickyWrap );
}
// onRenderHeader is defined, we need to do something about it (fixes #641) // onRenderHeader is defined, we need to do something about it (fixes #641)
if (c.onRenderHeader) { if (c.onRenderHeader) {