From e2ec19a8ece447d03c0f28e4b823671ffe8e7233 Mon Sep 17 00:00:00 2001 From: Chris Rogers Date: Mon, 7 Nov 2016 12:28:30 +0000 Subject: [PATCH 1/5] 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 after sorting, this is intended to be used with the 'sortTbody_sortRows' option set to true. This will allow the and it's child rows to be sorted while keeping the header row at the top of the . --- js/widgets/widget-sortTbodies.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/js/widgets/widget-sortTbodies.js b/js/widgets/widget-sortTbodies.js index a2295ce8f..8b49d9fdf 100644 --- a/js/widgets/widget-sortTbodies.js +++ b/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 */ @@ -38,6 +39,17 @@ // 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 lockHead = wo.sortTbody_lockHead; + var headClass = '.'+c.cssHeader; + + if ( lockHead ) { + c.$table.find( headClass ).each( function(){ + $( this ).parents( 'tbody' ).prepend( this ); + }); + } }); // detect parsers - in case the table contains only info-only tbodies From 3ad2fe4bcfaa489db69096f8af9b8092263741d8 Mon Sep 17 00:00:00 2001 From: Chris Rogers Date: Tue, 8 Nov 2016 20:31:45 +0000 Subject: [PATCH 2/5] 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. --- js/widgets/widget-sortTbodies.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/widgets/widget-sortTbodies.js b/js/widgets/widget-sortTbodies.js index 8b49d9fdf..a6b8de29e 100644 --- a/js/widgets/widget-sortTbodies.js +++ b/js/widgets/widget-sortTbodies.js @@ -43,10 +43,10 @@ .bind('sortEnd', function() { // Moves the head row back to the top of the tbody var lockHead = wo.sortTbody_lockHead; - var headClass = '.'+c.cssHeader; + var primaryRow = wo.sortTbody_primaryRow; - if ( lockHead ) { - c.$table.find( headClass ).each( function(){ + if ( primaryRow ) { + c.$table.find( primaryRow ).each( function(){ $( this ).parents( 'tbody' ).prepend( this ); }); } From 51d66cd46eee299a5e4b302d870f23c66545a1f9 Mon Sep 17 00:00:00 2001 From: Chris Rogers Date: Thu, 10 Nov 2016 07:31:38 +0000 Subject: [PATCH 3/5] Changed setting to test old code. --- js/jquery.tablesorter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 10ee4a716..8cf2dbade 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -85,7 +85,7 @@ cssAsc : '', cssDesc : '', cssNone : '', - cssHeader : '', + cssHeader : 'testHead', cssHeaderRow : '', cssProcessing : '', // processing icon applied to header during sort/filter From 991d4944128cb91dc777c0b9ff58d5a157fd6360 Mon Sep 17 00:00:00 2001 From: Chris Rogers Date: Thu, 17 Nov 2016 13:55:16 +0000 Subject: [PATCH 4/5] Roll back to master version. --- js/jquery.tablesorter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 8cf2dbade..10ee4a716 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -85,7 +85,7 @@ cssAsc : '', cssDesc : '', cssNone : '', - cssHeader : 'testHead', + cssHeader : '', cssHeaderRow : '', cssProcessing : '', // processing icon applied to header during sort/filter From 43b1cb5a335ad98cb35cee314a4c40e4678ed727 Mon Sep 17 00:00:00 2001 From: Chris Rogers Date: Thu, 17 Nov 2016 13:56:20 +0000 Subject: [PATCH 5/5] Widget sortTbodies - Removed `lockHead` var since it's only used once - Ammended `sortEnd` condition --- js/widgets/widget-sortTbodies.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/widgets/widget-sortTbodies.js b/js/widgets/widget-sortTbodies.js index a6b8de29e..b82516bf0 100644 --- a/js/widgets/widget-sortTbodies.js +++ b/js/widgets/widget-sortTbodies.js @@ -42,10 +42,9 @@ }) .bind('sortEnd', function() { // Moves the head row back to the top of the tbody - var lockHead = wo.sortTbody_lockHead; var primaryRow = wo.sortTbody_primaryRow; - if ( primaryRow ) { + if ( wo.sortTbody_lockHead && primaryRow ) { c.$table.find( primaryRow ).each( function(){ $( this ).parents( 'tbody' ).prepend( this ); });