Skip to content

Commit

Permalink
#59 - support tables with existing colgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoryak committed Apr 11, 2014
1 parent 1d14a00 commit 13d2037
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 38 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jquery.floatThead v1.2.5
jquery.floatThead v1.2.6
=================

Float the table header without special css. This plugin assumes nothing about your table markup and "just works" without losing your events or styles. Supports floating the header while scrolling within the window or while scrolling within a container with overflow.
Expand All @@ -22,7 +22,7 @@ Download / Install:

#### Download

[Latest Release](https://github.com/mkoryak/floatThead/archive/v1.2.5.zip)
[Latest Release](https://github.com/mkoryak/floatThead/archive/v1.2.6.zip)

Inside of that zip the following javascript files are of interest to you:

Expand Down Expand Up @@ -67,6 +67,7 @@ Features:
Requirements:
-------------


- jQuery 1.8.x or better (1.9 compliant) (or jQuery 1.7.x and jQuery UI core)
- IE8, IE9, IE10, IE11, FF10+ or Chrome15+.
- The following meta tag to placate IE: <code>&lt;meta http-equiv="X-UA-Compatible" content="IE=10; IE=9; IE=8; IE=7; IE=EDGE" /&gt;</code>
Expand All @@ -88,6 +89,19 @@ Watch for it.

Change Log
----------

### 1.2.6
- new stuff:
- added support for tables with existing `<colgroup>` elements
- added a grunt task to build dist to master

- bug fixes:
- https://github.com/mkoryak/floatThead/issues/57 - window resize issues on windows
- https://github.com/mkoryak/floatThead/issues/70 - better support for responsive tables
- https://github.com/mkoryak/floatThead/issues/71 - incorrectly unbinding events in destroy
- https://github.com/mkoryak/floatThead/issues/75 - dom leakage in destroy


### 1.2.5
- bug fixes:
- https://github.com/mkoryak/floatThead/issues/66
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery.floatThead",
"version": "1.2.5",
"version": "1.2.6",
"homepage": "http://mkoryak.github.io/floatThead/",
"authors": [
"Misha Koryak"
Expand Down
34 changes: 24 additions & 10 deletions dist/jquery.floatThead-slim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @preserve jQuery.floatThead 1.2.6 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/

/* @author Misha Koryak
Expand Down Expand Up @@ -201,7 +201,12 @@
var absoluteToFixedOnScroll = ieVersion <= 9 && !locked && useAbsolutePositioning; //on ie using absolute positioning doesnt look good with window scrolling, so we change positon to fixed on scroll, and then change it back to absolute when done.
var $floatTable = $("<table/>");
var $floatColGroup = $("<colgroup/>");
var $tableColGroup = $("<colgroup/>");
var $tableColGroup = $table.find('colgroup:first');
var existingColGroup = true;
if($tableColGroup.length == 0){
$tableColGroup = $("<colgroup/>");
existingColGroup = false;
}
var $fthRow = $('<fthrow style="display:table-row;height:0;"/>'); //created unstyled elements
var $floatContainer = $('<div style="overflow: hidden;"></div>');
var $newHeader = $("<thead/>");
Expand Down Expand Up @@ -303,11 +308,16 @@
* get the number of columns and also rebuild resizer rows if the count is different then the last count
*/
function columnNum(){
var $headerColumns = $header.find('tr:first>'+opts.cellTag);
var count = 0;
$headerColumns.each(function(){
count += parseInt(($(this).attr('colspan') || 1), 10);
});
var count, $headerColumns;
if(existingColGroup){
count = $tableColGroup.find('col').length;
} else {
$headerColumns = $header.find('tr:first>'+opts.cellTag);
count = 0;
$headerColumns.each(function(){
count += parseInt(($(this).attr('colspan') || 1), 10);
});
}
if(count != lastColumnCount){
lastColumnCount = count;
var cells = [], cols = [], psuedo = [];
Expand All @@ -328,7 +338,9 @@

$sizerRow.html(cells);
$sizerCells = $sizerRow.find("th");
$tableColGroup.html(cols);
if(!existingColGroup){
$tableColGroup.html(cols);
}
$tableCells = $tableColGroup.find('col');
$floatColGroup.html(cols);
$headerCells = $floatColGroup.find("col");
Expand Down Expand Up @@ -394,8 +406,10 @@
return function(){
var $rowCells = getSizingRow($table, $tableCells, $fthCells, ieVersion);
if($rowCells.length == numCols && numCols > 0){
for(i=0; i < numCols; i++){
$tableCells.eq(i).css('width', '');
if(!existingColGroup){
for(i=0; i < numCols; i++){
$tableCells.eq(i).css('width', '');
}
}
unfloat();
for(i=0; i < numCols; i++){
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.floatThead-slim.min.js

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions dist/jquery.floatThead.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @preserve jQuery.floatThead 1.2.6 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/

/* @author Misha Koryak
Expand Down Expand Up @@ -201,7 +201,12 @@
var absoluteToFixedOnScroll = ieVersion <= 9 && !locked && useAbsolutePositioning; //on ie using absolute positioning doesnt look good with window scrolling, so we change positon to fixed on scroll, and then change it back to absolute when done.
var $floatTable = $("<table/>");
var $floatColGroup = $("<colgroup/>");
var $tableColGroup = $("<colgroup/>");
var $tableColGroup = $table.find('colgroup:first');
var existingColGroup = true;
if($tableColGroup.length == 0){
$tableColGroup = $("<colgroup/>");
existingColGroup = false;
}
var $fthRow = $('<fthrow style="display:table-row;height:0;"/>'); //created unstyled elements
var $floatContainer = $('<div style="overflow: hidden;"></div>');
var $newHeader = $("<thead/>");
Expand Down Expand Up @@ -303,11 +308,16 @@
* get the number of columns and also rebuild resizer rows if the count is different then the last count
*/
function columnNum(){
var $headerColumns = $header.find('tr:first>'+opts.cellTag);
var count = 0;
$headerColumns.each(function(){
count += parseInt(($(this).attr('colspan') || 1), 10);
});
var count, $headerColumns;
if(existingColGroup){
count = $tableColGroup.find('col').length;
} else {
$headerColumns = $header.find('tr:first>'+opts.cellTag);
count = 0;
$headerColumns.each(function(){
count += parseInt(($(this).attr('colspan') || 1), 10);
});
}
if(count != lastColumnCount){
lastColumnCount = count;
var cells = [], cols = [], psuedo = [];
Expand All @@ -328,7 +338,9 @@

$sizerRow.html(cells);
$sizerCells = $sizerRow.find("th");
$tableColGroup.html(cols);
if(!existingColGroup){
$tableColGroup.html(cols);
}
$tableCells = $tableColGroup.find('col');
$floatColGroup.html(cols);
$headerCells = $floatColGroup.find("col");
Expand Down Expand Up @@ -394,8 +406,10 @@
return function(){
var $rowCells = getSizingRow($table, $tableCells, $fthCells, ieVersion);
if($rowCells.length == numCols && numCols > 0){
for(i=0; i < numCols; i++){
$tableCells.eq(i).css('width', '');
if(!existingColGroup){
for(i=0; i < numCols; i++){
$tableCells.eq(i).css('width', '');
}
}
unfloat();
for(i=0; i < numCols; i++){
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.floatThead.min.js

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions jquery.floatThead.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @preserve jQuery.floatThead 1.2.6 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/

/* @author Misha Koryak
Expand Down Expand Up @@ -201,7 +201,12 @@
var absoluteToFixedOnScroll = ieVersion <= 9 && !locked && useAbsolutePositioning; //on ie using absolute positioning doesnt look good with window scrolling, so we change positon to fixed on scroll, and then change it back to absolute when done.
var $floatTable = $("<table/>");
var $floatColGroup = $("<colgroup/>");
var $tableColGroup = $("<colgroup/>");
var $tableColGroup = $table.find('colgroup:first');
var existingColGroup = true;
if($tableColGroup.length == 0){
$tableColGroup = $("<colgroup/>");
existingColGroup = false;
}
var $fthRow = $('<fthrow style="display:table-row;height:0;"/>'); //created unstyled elements
var $floatContainer = $('<div style="overflow: hidden;"></div>');
var $newHeader = $("<thead/>");
Expand Down Expand Up @@ -303,11 +308,16 @@
* get the number of columns and also rebuild resizer rows if the count is different then the last count
*/
function columnNum(){
var $headerColumns = $header.find('tr:first>'+opts.cellTag);
var count = 0;
$headerColumns.each(function(){
count += parseInt(($(this).attr('colspan') || 1), 10);
});
var count, $headerColumns;
if(existingColGroup){
count = $tableColGroup.find('col').length;
} else {
$headerColumns = $header.find('tr:first>'+opts.cellTag);
count = 0;
$headerColumns.each(function(){
count += parseInt(($(this).attr('colspan') || 1), 10);
});
}
if(count != lastColumnCount){
lastColumnCount = count;
var cells = [], cols = [], psuedo = [];
Expand All @@ -328,7 +338,9 @@

$sizerRow.html(cells);
$sizerCells = $sizerRow.find("th");
$tableColGroup.html(cols);
if(!existingColGroup){
$tableColGroup.html(cols);
}
$tableCells = $tableColGroup.find('col');
$floatColGroup.html(cols);
$headerCells = $floatColGroup.find("col");
Expand Down Expand Up @@ -394,8 +406,10 @@
return function(){
var $rowCells = getSizingRow($table, $tableCells, $fthCells, ieVersion);
if($rowCells.length == numCols && numCols > 0){
for(i=0; i < numCols; i++){
$tableCells.eq(i).css('width', '');
if(!existingColGroup){
for(i=0; i < numCols; i++){
$tableCells.eq(i).css('width', '');
}
}
unfloat();
for(i=0; i < numCols; i++){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "floatthead",
"version": "1.2.5",
"version": "1.2.6",
"description": "locking table headers without special css",
"filename": "jquery.floatThead.js",
"dependencies": {},
Expand Down

0 comments on commit 13d2037

Please sign in to comment.