Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Version 1.3
## Version 1.3.1
- jquery.fixedheadertable.js

## Methods:
Expand All @@ -14,6 +14,7 @@
* fixedColumns - Number - Default: 0
* footer - Boolean - Default: false
* cloneHeadToFoot - Boolean - Default: false
* autoCreateThead - Boolean - Default: false
* autoShow - Boolean - Default: true
* altClass - String - Default: none
* themeClass - String - Default: none
Expand Down
106 changes: 70 additions & 36 deletions jquery.fixedheadertable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
* jQuery authoring guidelines
*
* Launch : October 2009
* Version : 1.3
* Version : 1.3.1
* Released: May 9th, 2011
*
*
* all CSS sizing (width,height) is done in pixels (px)
*/

/* jshint indent: 2, expr: true*/
/* global jQuery, navigator */
(function ($) {

$.fn.fixedHeaderTable = function (method) {
Expand All @@ -34,7 +35,8 @@
autoShow: true, // hide table after its created
footer: false, // show footer
cloneHeadToFoot: false, // clone head and use as footer
autoResize: false, // resize table if its parent wrapper changes size
autoResize: false, // resize table if its parent wrapper changes size,
autoCreateThead: false,
create: null // callback after plugin completes
};

Expand All @@ -48,6 +50,10 @@
// iterate through all the DOM elements we are attaching the plugin to
return this.each(function () {
var $self = $(this); // reference the jQuery version of the current DOM element

if(settings.autoCreateThead){
helpers._autoCreateThead($self);
}

if (helpers._isTable($self)) {
methods.setup.apply(this, Array.prototype.slice.call(arguments, 1));
Expand Down Expand Up @@ -79,9 +85,9 @@
settings.themeClassName = settings.themeClass;

if (settings.width.search('%') > -1) {
widthMinusScrollbar = $self.parent().width() - settings.scrollbarOffset;
widthMinusScrollbar = $self.parent().width() - settings.scrollbarOffset;
} else {
widthMinusScrollbar = settings.width - settings.scrollbarOffset;
widthMinusScrollbar = settings.width - settings.scrollbarOffset;
}

$self.css({
Expand All @@ -96,11 +102,11 @@

$wrapper = $self.closest('.fht-table-wrapper');

if(settings.fixedColumn == true && settings.fixedColumns <= 0) {
if(settings.fixedColumn === true && settings.fixedColumns <= 0) {
settings.fixedColumns = 1;
}

if (settings.fixedColumns > 0 && $wrapper.find('.fht-fixed-column').length == 0) {
if (settings.fixedColumns > 0 && $wrapper.find('.fht-fixed-column').length === 0) {
$self.wrap('<div class="fht-fixed-body"></div>');

$('<div class="fht-fixed-column"></div>').prependTo($wrapper);
Expand Down Expand Up @@ -147,7 +153,7 @@
* Check for footer
* Setup footer if present
*/
if (settings.footer == true) {
if (settings.footer === true) {
helpers._setupTableFooter($self, self, tableProps);

if (!$tfoot.length) {
Expand Down Expand Up @@ -315,6 +321,31 @@
return false;

},

/*
* return boolean
* True if a thead and tbody exist.
*/
_autoCreateThead: function($obj) {
var $self = $obj,
$newThead = $("<thead></thead>"),
$topRow,
hasThead = $self.find('thead').length > 0;

if (hasThead){
return;
}

$topRow = $obj
.children("tbody")
.children("tr")
.first();

$topRow.remove();

$newThead.append($topRow).prependTo($self);

},

/*
* return void
Expand All @@ -332,7 +363,7 @@

$fixedColumns.find('.fht-tbody table')
.css({
'margin-top': -$self.scrollTop()
'margin-top': -$self.scrollTop()
});
}

Expand Down Expand Up @@ -372,13 +403,13 @@
if (settings.includePadding) {
$obj.each(function() {
$(this).css({
'width': width == undefined ? $(this).width() + tableProps.border : width + tableProps.border
'width': width === undefined ? $(this).width() + tableProps.border : width + tableProps.border
});
});
} else {
$obj.each(function() {
$(this).css({
'width': width == undefined ? $(this).parent().width() + tableProps.border : width + tableProps.border
'width': width === undefined ? $(this).parent().width() + tableProps.border : width + tableProps.border
});
});
}
Expand Down Expand Up @@ -442,7 +473,7 @@
});

$firstTdChildren.each(function(index) {
if (index % settings.fixedColumns == 0) {
if (index % settings.fixedColumns === 0) {
$newRow = $('<tr></tr>').appendTo($tbody.find('tbody'));

if (settings.altClass && $(this).parent().hasClass(settings.altClass)) {
Expand All @@ -464,7 +495,7 @@
// bind mousewheel events
var maxTop = $fixedColumn.find('.fht-tbody .fht-table').height() - $fixedColumn.find('.fht-tbody').height();
$fixedColumn.find('.fht-table').bind('mousewheel', function(event, delta, deltaX, deltaY) {
if (deltaY == 0) {
if (deltaY === 0) {
return;
}
var top = parseInt($(this).css('marginTop'), 10) + (deltaY > 0 ? 120 : -120);
Expand All @@ -486,7 +517,7 @@
});

// setup clone footer with fixed column
if (settings.footer == true || settings.cloneHeadToFoot == true) {
if (settings.footer === true || settings.cloneHeadToFoot === true) {
var $firstTdFootChild = $fixedBody.find('.fht-tfoot tr > *:lt(' + settings.fixedColumns + ')'),
footwidth;

Expand Down Expand Up @@ -522,27 +553,30 @@
$divFoot.find('table.fht-table').addClass(settings.originalTable.attr('class'));

switch (true) {
case !$tfoot.length && settings.cloneHeadToFoot == true && settings.footer == true:

case !$tfoot.length && settings.cloneHeadToFoot === true && settings.footer === true:

var $divHead = $wrapper.find('div.fht-thead');
var $divHead = $wrapper.find('div.fht-thead');

$divFoot.empty();
$divHead.find('table')
.clone()
.appendTo($divFoot);
$divFoot.empty();
$divHead.find('table')
.clone()
.appendTo($divFoot);

break;
case $tfoot.length && settings.cloneHeadToFoot == false && settings.footer == true:
break;

case $tfoot.length && settings.cloneHeadToFoot === false && settings.footer === true:

$divFoot.find('table')
.append($tfoot)
.css({
'margin-top': -tableProps.border
});
$divFoot.find('table')
.append($tfoot)
.css({
'margin-top': -tableProps.border
});

helpers._setupClone($divFoot, tableProps.tfoot);
helpers._setupClone($divFoot, tableProps.tfoot);

break;
break;

}

},
Expand All @@ -554,14 +588,14 @@
*/
_getTableProps: function($obj) {
var tableProp = {
thead: {},
tbody: {},
tfoot: {},
border: 0
},
thead: {},
tbody: {},
tfoot: {},
border: 0
},
borderCollapse = 1;

if (settings.borderCollapse == true) {
if (settings.borderCollapse === true) {
borderCollapse = 2;
}

Expand Down Expand Up @@ -610,7 +644,7 @@
var padding = Math.max((($(this).innerWidth() - $(this).width()) / 2), settings.scrollbarOffset);
$(this).css({
'padding-right': padding + 'px'
});
});
}
});
},
Expand Down
Loading