Skip to content

Commit

Permalink
Tbodysort widget enhancement. (#1312)
Browse files Browse the repository at this point in the history
* Enhancement/LockTbodyHeader

Added two new variables to hold the lockhead option and the head row class (defined in cssHeader).
If the new widget option 'sortTbody_lockHead' is true, the header row will be moved back to the top of the <tbody> after sorting, this is intended to be used with the 'sortTbody_sortRows' option set to true.
This will allow the <tbody> and it's child rows to be sorted while keeping the header row at the top of the <tbody>.

* The new lockHead option now used the `sortTbody_primaryRow` value instead of the `cssHeader` value.
This means the new widget option can be used out-of-the-box, meaning the user won't need to change any default parameters in the js files.

* Changed setting to test old code.

* Roll back to master version.

* Widget sortTbodies
  - Removed `lockHead` var since it's only used once
  - Ammended `sortEnd` condition
  • Loading branch information
Chris Rogers authored and Mottie committed Nov 17, 2016
1 parent f8a205c commit 43979d4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion js/widgets/widget-sortTbodies.js
@@ -1,6 +1,7 @@
/*! tablesorter tbody sorting widget (BETA) - 11/22/2015 (v2.24.6)
/*! tablesorter tbody sorting widget (BETA) - 11/07/2016 (v2.24.7)
* Requires tablesorter v2.22.2+ and jQuery 1.4+
* by Rob Garrison
* Contributors: Chris Rogers
*/
/*jshint browser:true, jquery:true, unused:false */
/*global jQuery: false */
Expand Down Expand Up @@ -38,6 +39,16 @@
// find parsers for each column
ts.sortTbodies.setTbodies( c, wo );
ts.updateCache( c, null, c.$tbodies );
})
.bind('sortEnd', function() {
// Moves the head row back to the top of the tbody
var primaryRow = wo.sortTbody_primaryRow;

if ( wo.sortTbody_lockHead && primaryRow ) {
c.$table.find( primaryRow ).each( function(){
$( this ).parents( 'tbody' ).prepend( this );
});
}
});

// detect parsers - in case the table contains only info-only tbodies
Expand Down

0 comments on commit 43979d4

Please sign in to comment.