support multiple fixed columns - use {'fixedColumns': n}
parent
c30fe94be0
commit
cb3cf67242
|
@ -1,22 +1,22 @@
|
||||||
/*!
|
/*!
|
||||||
* jquery.fixedHeaderTable. The jQuery fixedHeaderTable plugin
|
* jquery.fixedHeaderTable. The jQuery fixedHeaderTable plugin
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011 Mark Malek
|
* Copyright (c) 2011 Mark Malek
|
||||||
* http://fixedheadertable.com
|
* http://fixedheadertable.com
|
||||||
*
|
*
|
||||||
* Licensed under MIT
|
* Licensed under MIT
|
||||||
* http://www.opensource.org/licenses/mit-license.php
|
* http://www.opensource.org/licenses/mit-license.php
|
||||||
*
|
*
|
||||||
* http://docs.jquery.com/Plugins/Authoring
|
* http://docs.jquery.com/Plugins/Authoring
|
||||||
* jQuery authoring guidelines
|
* jQuery authoring guidelines
|
||||||
*
|
*
|
||||||
* Launch : October 2009
|
* Launch : October 2009
|
||||||
* Version : 1.3
|
* Version : 1.3
|
||||||
* Released: May 9th, 2011
|
* Released: May 9th, 2011
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* all CSS sizing (width,height) is done in pixels (px)
|
* all CSS sizing (width,height) is done in pixels (px)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@
|
||||||
themeClass: 'fht-default',
|
themeClass: 'fht-default',
|
||||||
|
|
||||||
borderCollapse: true,
|
borderCollapse: true,
|
||||||
fixedColumn: false, // fixed first column
|
fixedColumns: 0, // fixed first columns
|
||||||
sortable: false,
|
sortable: false,
|
||||||
autoShow: true, // hide table after its created
|
autoShow: true, // hide table after its created
|
||||||
footer: false, // show footer
|
footer: false, // show footer
|
||||||
cloneHeadToFoot: false, // clone head and use as 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
|
||||||
|
|
||||||
create: null // callback after plugin completes
|
create: null // callback after plugin completes
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
|
|
||||||
var $self = $(this), // reference the jQuery version of the current DOM element
|
var $self = $(this), // reference the jQuery version of the current DOM element
|
||||||
self = this; // reference to the actual DOM element
|
self = this; // reference to the actual DOM element
|
||||||
|
|
||||||
if ( helpers._isTable($self) ) {
|
if ( helpers._isTable($self) ) {
|
||||||
methods.setup.apply(this, Array.prototype.slice.call(arguments, 1));
|
methods.setup.apply(this, Array.prototype.slice.call(arguments, 1));
|
||||||
|
@ -67,38 +67,38 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup table structure for fixed headers and optional footer
|
* Setup table structure for fixed headers and optional footer
|
||||||
*/
|
*/
|
||||||
setup: function( options ) {
|
setup: function( options ) {
|
||||||
var $self = $(this),
|
var $self = $(this),
|
||||||
self = this,
|
self = this,
|
||||||
$thead = $self.find('thead'),
|
$thead = $self.find('thead'),
|
||||||
$tfoot = $self.find('tfoot'),
|
$tfoot = $self.find('tfoot'),
|
||||||
$tbody = $self.find('tbody'),
|
$tbody = $self.find('tbody'),
|
||||||
$wrapper,
|
$wrapper,
|
||||||
$divHead,
|
$divHead,
|
||||||
$divFoot,
|
$divFoot,
|
||||||
$divBody,
|
$divBody,
|
||||||
$fixedHeadRow,
|
$fixedHeadRow,
|
||||||
$temp,
|
$temp,
|
||||||
tfootHeight = 0;
|
tfootHeight = 0;
|
||||||
|
|
||||||
settings.includePadding = helpers._isPaddingIncludedWithWidth();
|
settings.includePadding = helpers._isPaddingIncludedWithWidth();
|
||||||
settings.scrollbarOffset = helpers._getScrollbarWidth();
|
settings.scrollbarOffset = helpers._getScrollbarWidth();
|
||||||
settings.themeClassName = settings.themeClass;
|
settings.themeClassName = settings.themeClass;
|
||||||
|
|
||||||
if ( settings.width.search('%') > -1 ) {
|
if ( settings.width.search('%') > -1 ) {
|
||||||
var widthMinusScrollbar = $self.parent().width() - settings.scrollbarOffset;
|
var widthMinusScrollbar = $self.parent().width() - settings.scrollbarOffset;
|
||||||
} else {
|
} else {
|
||||||
var widthMinusScrollbar = settings.width - settings.scrollbarOffset;
|
var widthMinusScrollbar = settings.width - settings.scrollbarOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self.css({
|
$self.css({
|
||||||
width: widthMinusScrollbar
|
width: widthMinusScrollbar
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if ( !$self.closest('.fht-table-wrapper').length ) {
|
if ( !$self.closest('.fht-table-wrapper').length ) {
|
||||||
$self.addClass('fht-table');
|
$self.addClass('fht-table');
|
||||||
|
@ -107,40 +107,40 @@
|
||||||
|
|
||||||
$wrapper = $self.closest('.fht-table-wrapper');
|
$wrapper = $self.closest('.fht-table-wrapper');
|
||||||
|
|
||||||
if ( settings.fixedColumn == true && $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>');
|
$self.wrap('<div class="fht-fixed-body"></div>');
|
||||||
|
|
||||||
var $fixedColumn = $('<div class="fht-fixed-column"></div>').prependTo($wrapper),
|
var $fixedColumns = $('<div class="fht-fixed-column"></div>').prependTo($wrapper),
|
||||||
$fixedBody = $wrapper.find('.fht-fixed-body');
|
$fixedBody = $wrapper.find('.fht-fixed-body');
|
||||||
}
|
}
|
||||||
|
|
||||||
$wrapper.css({
|
$wrapper.css({
|
||||||
width: settings.width,
|
width: settings.width,
|
||||||
height: settings.height
|
height: settings.height
|
||||||
})
|
})
|
||||||
.addClass(settings.themeClassName);
|
.addClass(settings.themeClassName);
|
||||||
|
|
||||||
if ( !$self.hasClass('fht-table-init') ) {
|
if ( !$self.hasClass('fht-table-init') ) {
|
||||||
|
|
||||||
$self.wrap('<div class="fht-tbody"></div>');
|
$self.wrap('<div class="fht-tbody"></div>');
|
||||||
|
|
||||||
}
|
}
|
||||||
$divBody = $self.closest('.fht-tbody');
|
$divBody = $self.closest('.fht-tbody');
|
||||||
|
|
||||||
var tableProps = helpers._getTableProps($self);
|
var tableProps = helpers._getTableProps($self);
|
||||||
|
|
||||||
helpers._setupClone( $divBody, tableProps.tbody );
|
helpers._setupClone( $divBody, tableProps.tbody );
|
||||||
|
|
||||||
if ( !$self.hasClass('fht-table-init') ) {
|
if ( !$self.hasClass('fht-table-init') ) {
|
||||||
if ( settings.fixedColumn == true ) {
|
if ( settings.fixedColumns > 0 ) {
|
||||||
$divHead = $('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo($fixedBody);
|
$divHead = $('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo($fixedBody);
|
||||||
} else {
|
} else {
|
||||||
$divHead = $('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo($wrapper);
|
$divHead = $('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo($wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
$thead.clone().appendTo($divHead.find('table'));
|
$thead.clone().appendTo($divHead.find('table'));
|
||||||
} else {
|
} else {
|
||||||
$divHead = $wrapper.find('div.fht-thead');
|
$divHead = $wrapper.find('div.fht-thead');
|
||||||
}
|
}
|
||||||
|
|
||||||
helpers._setupClone( $divHead, tableProps.thead );
|
helpers._setupClone( $divHead, tableProps.thead );
|
||||||
|
@ -155,29 +155,29 @@
|
||||||
*/
|
*/
|
||||||
if ( settings.footer == true ) {
|
if ( settings.footer == true ) {
|
||||||
|
|
||||||
helpers._setupTableFooter( $self, self, tableProps );
|
helpers._setupTableFooter( $self, self, tableProps );
|
||||||
|
|
||||||
if ( !$tfoot.length ) {
|
if ( !$tfoot.length ) {
|
||||||
$tfoot = $wrapper.find('div.fht-tfoot table');
|
$tfoot = $wrapper.find('div.fht-tfoot table');
|
||||||
}
|
}
|
||||||
|
|
||||||
tfootHeight = $tfoot.outerHeight(true);
|
tfootHeight = $tfoot.outerHeight(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tbodyHeight = $wrapper.height() - $thead.outerHeight(true) - tfootHeight - tableProps.border;
|
var tbodyHeight = $wrapper.height() - $thead.outerHeight(true) - tfootHeight - tableProps.border;
|
||||||
|
|
||||||
$divBody.css({
|
$divBody.css({
|
||||||
'height': tbodyHeight
|
'height': tbodyHeight
|
||||||
});
|
});
|
||||||
|
|
||||||
$self.addClass('fht-table-init');
|
$self.addClass('fht-table-init');
|
||||||
|
|
||||||
if ( typeof(settings.altClass) !== 'undefined' ) {
|
if ( typeof(settings.altClass) !== 'undefined' ) {
|
||||||
methods.altRows.apply( self );
|
methods.altRows.apply( self );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( settings.fixedColumn == true ) {
|
if ( settings.fixedColumns > 0 ) {
|
||||||
helpers._setupFixedColumn( $self, self, tableProps );
|
helpers._setupFixedColumn( $self, self, tableProps );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !settings.autoShow ) {
|
if ( !settings.autoShow ) {
|
||||||
|
@ -195,7 +195,7 @@
|
||||||
*/
|
*/
|
||||||
resize: function( options ) {
|
resize: function( options ) {
|
||||||
var $self = $(this),
|
var $self = $(this),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
|
@ -205,12 +205,12 @@
|
||||||
*/
|
*/
|
||||||
altRows: function( arg1 ) {
|
altRows: function( arg1 ) {
|
||||||
var $self = $(this),
|
var $self = $(this),
|
||||||
self = this,
|
self = this,
|
||||||
altClass = ( typeof(arg1) !== 'undefined' ) ? arg1 : settings.altClass;
|
altClass = ( typeof(arg1) !== 'undefined' ) ? arg1 : settings.altClass;
|
||||||
|
|
||||||
$self.closest('.fht-table-wrapper')
|
$self.closest('.fht-table-wrapper')
|
||||||
.find('tbody tr:odd:not(:hidden)')
|
.find('tbody tr:odd:not(:hidden)')
|
||||||
.addClass(altClass);
|
.addClass(altClass);
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -218,33 +218,33 @@
|
||||||
*/
|
*/
|
||||||
show: function( arg1, arg2, arg3 ) {
|
show: function( arg1, arg2, arg3 ) {
|
||||||
var $self = $(this),
|
var $self = $(this),
|
||||||
self = this,
|
self = this,
|
||||||
$wrapper = $self.closest('.fht-table-wrapper');
|
$wrapper = $self.closest('.fht-table-wrapper');
|
||||||
|
|
||||||
// User provided show duration without a specific effect
|
// User provided show duration without a specific effect
|
||||||
if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'number' ) {
|
if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'number' ) {
|
||||||
|
|
||||||
$wrapper.show(arg1, function() {
|
$wrapper.show(arg1, function() {
|
||||||
$.isFunction(arg2) && arg2.call(this);
|
$.isFunction(arg2) && arg2.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
} else if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'string'
|
} else if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'string'
|
||||||
&& typeof(arg2) !== 'undefined' && typeof(arg2) === 'number' ) {
|
&& typeof(arg2) !== 'undefined' && typeof(arg2) === 'number' ) {
|
||||||
// User provided show duration with an effect
|
// User provided show duration with an effect
|
||||||
|
|
||||||
$wrapper.show(arg1, arg2, function() {
|
$wrapper.show(arg1, arg2, function() {
|
||||||
$.isFunction(arg3) && arg3.call(this);
|
$.isFunction(arg3) && arg3.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$self.closest('.fht-table-wrapper')
|
$self.closest('.fht-table-wrapper')
|
||||||
.show();
|
.show();
|
||||||
$.isFunction(arg1) && arg1.call(this);
|
$.isFunction(arg1) && arg1.call(this);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
|
@ -254,33 +254,33 @@
|
||||||
*/
|
*/
|
||||||
hide: function( arg1, arg2, arg3 ) {
|
hide: function( arg1, arg2, arg3 ) {
|
||||||
var $self = $(this),
|
var $self = $(this),
|
||||||
self = this,
|
self = this,
|
||||||
$wrapper = $self.closest('.fht-table-wrapper');
|
$wrapper = $self.closest('.fht-table-wrapper');
|
||||||
|
|
||||||
// User provided show duration without a specific effect
|
// User provided show duration without a specific effect
|
||||||
if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'number' ) {
|
if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'number' ) {
|
||||||
$wrapper.hide(arg1, function() {
|
$wrapper.hide(arg1, function() {
|
||||||
$.isFunction(arg3) && arg3.call(this);
|
$.isFunction(arg3) && arg3.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
return self;
|
|
||||||
} else if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'string'
|
|
||||||
&& typeof(arg2) !== 'undefined' && typeof(arg2) === 'number' ) {
|
|
||||||
|
|
||||||
$wrapper.hide(arg1, arg2, function() {
|
|
||||||
$.isFunction(arg3) && arg3.call(this);
|
|
||||||
});
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self.closest('.fht-table-wrapper')
|
return self;
|
||||||
.hide();
|
} else if ( typeof(arg1) !== 'undefined' && typeof(arg1) === 'string'
|
||||||
|
&& typeof(arg2) !== 'undefined' && typeof(arg2) === 'number' ) {
|
||||||
$.isFunction(arg3) && arg3.call(this);
|
|
||||||
|
$wrapper.hide(arg1, arg2, function() {
|
||||||
|
$.isFunction(arg3) && arg3.call(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self.closest('.fht-table-wrapper')
|
||||||
|
.hide();
|
||||||
|
|
||||||
|
$.isFunction(arg3) && arg3.call(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -289,15 +289,15 @@
|
||||||
*/
|
*/
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
var $self = $(this),
|
var $self = $(this),
|
||||||
self = this,
|
self = this,
|
||||||
$wrapper = $self.closest('.fht-table-wrapper');
|
$wrapper = $self.closest('.fht-table-wrapper');
|
||||||
|
|
||||||
$self.insertBefore($wrapper)
|
$self.insertBefore($wrapper)
|
||||||
.removeAttr('style')
|
.removeAttr('style')
|
||||||
.append($wrapper.find('tfoot'))
|
.append($wrapper.find('tfoot'))
|
||||||
.removeClass('fht-table fht-table-init')
|
.removeClass('fht-table fht-table-init')
|
||||||
.find('.fht-cell')
|
.find('.fht-cell')
|
||||||
.remove();
|
.remove();
|
||||||
|
|
||||||
$wrapper.remove();
|
$wrapper.remove();
|
||||||
|
|
||||||
|
@ -309,15 +309,15 @@
|
||||||
// private methods
|
// private methods
|
||||||
var helpers = {
|
var helpers = {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return boolean
|
* return boolean
|
||||||
* True if a thead and tbody exist.
|
* True if a thead and tbody exist.
|
||||||
*/
|
*/
|
||||||
_isTable: function( $obj ) {
|
_isTable: function( $obj ) {
|
||||||
var $self = $obj,
|
var $self = $obj,
|
||||||
hasTable = $self.is('table'),
|
hasTable = $self.is('table'),
|
||||||
hasThead = $self.find('thead').length > 0,
|
hasThead = $self.find('thead').length > 0,
|
||||||
hasTbody = $self.find('tbody').length > 0;
|
hasTbody = $self.find('tbody').length > 0;
|
||||||
|
|
||||||
if ( hasTable && hasThead && hasTbody ) {
|
if ( hasTable && hasThead && hasTbody ) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -333,31 +333,31 @@
|
||||||
*/
|
*/
|
||||||
_bindScroll: function( $obj, tableProps ) {
|
_bindScroll: function( $obj, tableProps ) {
|
||||||
var $self = $obj,
|
var $self = $obj,
|
||||||
$wrapper = $self.closest('.fht-table-wrapper'),
|
$wrapper = $self.closest('.fht-table-wrapper'),
|
||||||
$thead = $self.siblings('.fht-thead'),
|
$thead = $self.siblings('.fht-thead'),
|
||||||
$tfoot = $self.siblings('.fht-tfoot');
|
$tfoot = $self.siblings('.fht-tfoot');
|
||||||
|
|
||||||
$self.bind('scroll', function() {
|
$self.bind('scroll', function() {
|
||||||
if ( settings.fixedColumn == true ) {
|
if ( settings.fixedColumns > 0 ) {
|
||||||
var $fixedColumn = $wrapper.find('.fht-fixed-column');
|
var $fixedColumns = $wrapper.find('.fht-fixed-column');
|
||||||
|
|
||||||
$fixedColumn.find('.fht-tbody table')
|
$fixedColumns.find('.fht-tbody table')
|
||||||
.css({
|
.css({
|
||||||
'margin-top': -$self.scrollTop()
|
'margin-top': -$self.scrollTop()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$thead.find('table')
|
$thead.find('table')
|
||||||
.css({
|
.css({
|
||||||
'margin-left': -this.scrollLeft
|
'margin-left': -this.scrollLeft
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( settings.cloneHeadToFoot ) {
|
if ( settings.cloneHeadToFoot ) {
|
||||||
$tfoot.find('table')
|
$tfoot.find('table')
|
||||||
.css({
|
.css({
|
||||||
'margin-left': -this.scrollLeft
|
'margin-left': -this.scrollLeft
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -366,13 +366,13 @@
|
||||||
*/
|
*/
|
||||||
_fixHeightWithCss: function ( $obj, tableProps ) {
|
_fixHeightWithCss: function ( $obj, tableProps ) {
|
||||||
if ( settings.includePadding ) {
|
if ( settings.includePadding ) {
|
||||||
$obj.css({
|
$obj.css({
|
||||||
'height': $obj.height() + tableProps.border
|
'height': $obj.height() + tableProps.border
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$obj.css({
|
$obj.css({
|
||||||
'height': $obj.parent().height() + tableProps.border
|
'height': $obj.parent().height() + tableProps.border
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -381,88 +381,100 @@
|
||||||
*/
|
*/
|
||||||
_fixWidthWithCss: function( $obj, tableProps ) {
|
_fixWidthWithCss: function( $obj, tableProps ) {
|
||||||
if ( settings.includePadding ) {
|
if ( settings.includePadding ) {
|
||||||
$obj.css({
|
$obj.css({
|
||||||
'width': $obj.width() + tableProps.border
|
'width': $obj.width() + tableProps.border
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$obj.css({
|
$obj.css({
|
||||||
'width': $obj.parent().width() + tableProps.border
|
'width': $obj.parent().width() + tableProps.border
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return void
|
* return void
|
||||||
*/
|
*/
|
||||||
_setupFixedColumn: function ( $obj, obj, tableProps ) {
|
_setupFixedColumn: function ( $obj, obj, tableProps ) {
|
||||||
var $self = $obj,
|
var $self = $obj,
|
||||||
self = obj,
|
self = obj,
|
||||||
$wrapper = $self.closest('.fht-table-wrapper'),
|
$wrapper = $self.closest('.fht-table-wrapper'),
|
||||||
$fixedBody = $wrapper.find('.fht-fixed-body'),
|
$fixedBody = $wrapper.find('.fht-fixed-body'),
|
||||||
$fixedColumn = $wrapper.find('.fht-fixed-column'),
|
$fixedColumn = $wrapper.find('.fht-fixed-column'),
|
||||||
$thead = $('<div class="fht-thead"><table class="fht-table"><thead><tr></tr></thead></table></div>'),
|
$thead = $('<div class="fht-thead"><table class="fht-table"><thead><tr></tr></thead></table></div>'),
|
||||||
$tbody = $('<div class="fht-tbody"><table class="fht-table"><tbody></tbody></table></div>'),
|
$tbody = $('<div class="fht-tbody"><table class="fht-table"><tbody></tbody></table></div>'),
|
||||||
$tfoot = $('<div class="fht-tfoot"><table class="fht-table"><thead><tr></tr></thead></table></div>'),
|
$tfoot = $('<div class="fht-tfoot"><table class="fht-table"><thead><tr></tr></thead></table></div>'),
|
||||||
$firstThChild = $fixedBody.find('.fht-thead thead tr th:first-child'),
|
$firstThChildren,// = $fixedBody.find('.fht-thead thead tr th:first-child'),
|
||||||
$firstTdChildren,
|
$firstTdChildren,
|
||||||
fixedColumnWidth = $firstThChild.outerWidth(true) + tableProps.border,
|
fixedColumnWidth,// = $firstThChild.outerWidth(true) + tableProps.border,
|
||||||
fixedBodyWidth = $wrapper.width(),
|
fixedBodyWidth = $wrapper.width(),
|
||||||
fixedBodyHeight = $fixedBody.find('.fht-tbody').height() - settings.scrollbarOffset,
|
fixedBodyHeight = $fixedBody.find('.fht-tbody').height() - settings.scrollbarOffset,
|
||||||
$newRow;
|
$newRow;
|
||||||
|
|
||||||
// Fix cell heights
|
$firstThChildren = $fixedBody.find('.fht-thead thead tr th:lt(' + settings.fixedColumns + ')');
|
||||||
helpers._fixHeightWithCss( $firstThChild, tableProps );
|
fixedColumnWidth = settings.fixedColumns * tableProps.border;
|
||||||
helpers._fixWidthWithCss( $firstThChild, tableProps );
|
$firstThChildren.each(function(index) {
|
||||||
$firstTdChildren = $fixedBody.find('tbody tr td:first-child')
|
fixedColumnWidth += $(this).outerWidth(true);
|
||||||
.each( function(index) {
|
});
|
||||||
helpers._fixHeightWithCss( $(this), tableProps );
|
|
||||||
helpers._fixWidthWithCss( $(this), tableProps );
|
// Fix cell heights
|
||||||
});
|
helpers._fixHeightWithCss( $firstThChildren, tableProps );
|
||||||
|
helpers._fixWidthWithCss( $firstThChildren, tableProps );
|
||||||
// clone header
|
|
||||||
$thead.appendTo($fixedColumn)
|
firstTdChildrenSelector = 'tbody tr td:not(:nth-child(n+' + (settings.fixedColumns + 1) + '))';
|
||||||
.find('tr')
|
$firstTdChildren = $fixedBody.find(firstTdChildrenSelector)
|
||||||
.append($firstThChild.clone());
|
.each( function(index) {
|
||||||
|
helpers._fixHeightWithCss( $(this), tableProps );
|
||||||
$tbody.appendTo($fixedColumn)
|
helpers._fixWidthWithCss( $(this), tableProps );
|
||||||
.css({
|
});
|
||||||
'margin-top': -1,
|
|
||||||
'height': fixedBodyHeight + tableProps.border
|
// clone header
|
||||||
});
|
$thead.appendTo($fixedColumn)
|
||||||
$firstTdChildren.each(function(index) {
|
.find('tr')
|
||||||
$newRow = $('<tr></tr>').appendTo($tbody.find('tbody'));
|
.append($firstThChildren.clone());
|
||||||
|
|
||||||
if ( settings.altClass && $(this).parent().hasClass(settings.altClass) ) {
|
$tbody.appendTo($fixedColumn)
|
||||||
$newRow.addClass(settings.altClass);
|
.css({
|
||||||
}
|
'margin-top': -1,
|
||||||
|
'height': fixedBodyHeight + tableProps.border
|
||||||
$(this).clone()
|
});
|
||||||
.appendTo($newRow);
|
|
||||||
});
|
var $newRow;
|
||||||
|
$firstTdChildren.each(function(index) {
|
||||||
// set width of fixed column wrapper
|
if (index % settings.fixedColumns == 0) {
|
||||||
$fixedColumn.css({
|
$newRow = $('<tr></tr>').appendTo($tbody.find('tbody'));
|
||||||
'width': fixedColumnWidth
|
|
||||||
});
|
if ( settings.altClass && $(this).parent().hasClass(settings.altClass) ) {
|
||||||
|
$newRow.addClass(settings.altClass);
|
||||||
// set width of body table wrapper
|
}
|
||||||
$fixedBody.css({
|
}
|
||||||
'width': fixedBodyWidth
|
|
||||||
});
|
$(this).clone()
|
||||||
|
.appendTo($newRow);
|
||||||
// setup clone footer with fixed column
|
});
|
||||||
if ( settings.footer == true || settings.cloneHeadToFoot == true ) {
|
|
||||||
var $firstTdFootChild = $fixedBody.find('.fht-tfoot thead tr th:first-child');
|
// set width of fixed column wrapper
|
||||||
|
$fixedColumn.css({
|
||||||
helpers._fixHeightWithCss( $firstTdFootChild, tableProps );
|
'width': fixedColumnWidth
|
||||||
$tfoot.appendTo($fixedColumn)
|
});
|
||||||
.find('tr')
|
|
||||||
.append($firstTdFootChild.clone());
|
// set width of body table wrapper
|
||||||
$tfoot.css({
|
$fixedBody.css({
|
||||||
'top': settings.scrollbarOffset
|
'width': fixedBodyWidth
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
// setup clone footer with fixed column
|
||||||
|
if ( settings.footer == true || settings.cloneHeadToFoot == true ) {
|
||||||
|
var $firstTdFootChild = $fixedBody.find('.fht-tfoot thead tr th:lt(' + settings.fixedColumns + ')');
|
||||||
|
|
||||||
|
helpers._fixHeightWithCss( $firstTdFootChild, tableProps );
|
||||||
|
$tfoot.appendTo($fixedColumn)
|
||||||
|
.find('tr')
|
||||||
|
.append($firstTdFootChild.clone());
|
||||||
|
$tfoot.css({
|
||||||
|
'top': settings.scrollbarOffset
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return void
|
* return void
|
||||||
|
@ -470,41 +482,41 @@
|
||||||
_setupTableFooter: function ( $obj, obj, tableProps ) {
|
_setupTableFooter: function ( $obj, obj, tableProps ) {
|
||||||
|
|
||||||
var $self = $obj,
|
var $self = $obj,
|
||||||
self = obj,
|
self = obj,
|
||||||
$wrapper = $self.closest('.fht-table-wrapper'),
|
$wrapper = $self.closest('.fht-table-wrapper'),
|
||||||
$tfoot = $self.find('tfoot'),
|
$tfoot = $self.find('tfoot'),
|
||||||
$divFoot = $wrapper.find('div.fht-tfoot');
|
$divFoot = $wrapper.find('div.fht-tfoot');
|
||||||
|
|
||||||
if ( !$divFoot.length ) {
|
if ( !$divFoot.length ) {
|
||||||
if ( settings.fixedColumn == true ) {
|
if ( settings.fixedColumns > 0 ) {
|
||||||
$divFoot = $('<div class="fht-tfoot"><table class="fht-table"></table></div>').appendTo($wrapper.find('.fht-fixed-body'));
|
$divFoot = $('<div class="fht-tfoot"><table class="fht-table"></table></div>').appendTo($wrapper.find('.fht-fixed-body'));
|
||||||
} else {
|
} else {
|
||||||
$divFoot = $('<div class="fht-tfoot"><table class="fht-table"></table></div>').appendTo($wrapper);
|
$divFoot = $('<div class="fht-tfoot"><table class="fht-table"></table></div>').appendTo($wrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (true) {
|
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();
|
$divFoot.empty();
|
||||||
$divHead.find('table')
|
$divHead.find('table')
|
||||||
.clone()
|
.clone()
|
||||||
.appendTo($divFoot);
|
.appendTo($divFoot);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case $tfoot.length && settings.cloneHeadToFoot == false && settings.footer == true:
|
case $tfoot.length && settings.cloneHeadToFoot == false && settings.footer == true:
|
||||||
|
|
||||||
$divFoot.find('table')
|
$divFoot.find('table')
|
||||||
.append($tfoot)
|
.append($tfoot)
|
||||||
.css({
|
.css({
|
||||||
'margin-top': -tableProps.border
|
'margin-top': -tableProps.border
|
||||||
});
|
});
|
||||||
|
|
||||||
helpers._setupClone( $divFoot, tableProps.tfoot );
|
helpers._setupClone( $divFoot, tableProps.tfoot );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -524,17 +536,17 @@
|
||||||
borderCollapse = 1;
|
borderCollapse = 1;
|
||||||
|
|
||||||
if ( settings.borderCollapse == true ) {
|
if ( settings.borderCollapse == true ) {
|
||||||
borderCollapse = 2;
|
borderCollapse = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
tableProp.border = ( $obj.find('th:first-child').outerWidth() - $obj.find('th:first-child').innerWidth() ) / borderCollapse;
|
tableProp.border = ( $obj.find('th:first-child').outerWidth() - $obj.find('th:first-child').innerWidth() ) / borderCollapse;
|
||||||
|
|
||||||
$obj.find('thead tr:first-child th').each(function(index) {
|
$obj.find('thead tr:first-child th').each(function(index) {
|
||||||
tableProp.thead[index] = $(this).width() + tableProp.border;
|
tableProp.thead[index] = $(this).width() + tableProp.border;
|
||||||
});
|
});
|
||||||
|
|
||||||
$obj.find('tfoot tr:first-child td').each(function(index) {
|
$obj.find('tfoot tr:first-child td').each(function(index) {
|
||||||
tableProp.tfoot[index] = $(this).width() + tableProp.border;
|
tableProp.tfoot[index] = $(this).width() + tableProp.border;
|
||||||
});
|
});
|
||||||
|
|
||||||
$obj.find('tbody tr:first-child td').each(function(index) {
|
$obj.find('tbody tr:first-child td').each(function(index) {
|
||||||
|
@ -550,16 +562,16 @@
|
||||||
*/
|
*/
|
||||||
_setupClone: function( $obj, cellArray ) {
|
_setupClone: function( $obj, cellArray ) {
|
||||||
var $self = $obj,
|
var $self = $obj,
|
||||||
selector = ( $self.find('thead').length ) ?
|
selector = ( $self.find('thead').length ) ?
|
||||||
'thead th' :
|
'thead th' :
|
||||||
( $self.find('tfoot').length ) ?
|
( $self.find('tfoot').length ) ?
|
||||||
'tfoot td' :
|
'tfoot td' :
|
||||||
'tbody td',
|
'tbody td',
|
||||||
$cell;
|
$cell;
|
||||||
|
|
||||||
$self.find(selector).each(function(index) {
|
$self.find(selector).each(function(index) {
|
||||||
$cell = ( $(this).find('div.fht-cell').length ) ? $(this).find('div.fht-cell') : $('<div class="fht-cell"></div>').appendTo($(this));
|
$cell = ( $(this).find('div.fht-cell').length ) ? $(this).find('div.fht-cell') : $('<div class="fht-cell"></div>').appendTo($(this));
|
||||||
|
|
||||||
$cell.css({
|
$cell.css({
|
||||||
'width': parseInt(cellArray[index])
|
'width': parseInt(cellArray[index])
|
||||||
});
|
});
|
||||||
|
@ -571,7 +583,7 @@
|
||||||
if ( !$(this).closest('.fht-tbody').length && $(this).is(':last-child') && !$(this).closest('.fht-fixed-column').length ) {
|
if ( !$(this).closest('.fht-tbody').length && $(this).is(':last-child') && !$(this).closest('.fht-fixed-column').length ) {
|
||||||
var padding = ( ( $(this).innerWidth() - $(this).width() ) / 2 ) + settings.scrollbarOffset;
|
var padding = ( ( $(this).innerWidth() - $(this).width() ) / 2 ) + settings.scrollbarOffset;
|
||||||
$(this).css({
|
$(this).css({
|
||||||
'padding-right': padding + 'px'
|
'padding-right': padding + 'px'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -585,23 +597,23 @@
|
||||||
*/
|
*/
|
||||||
_isPaddingIncludedWithWidth: function() {
|
_isPaddingIncludedWithWidth: function() {
|
||||||
var $obj = $('<table class="fht-table"><tr><td style="padding: 10px; font-size: 10px;">test</td></tr></table>'),
|
var $obj = $('<table class="fht-table"><tr><td style="padding: 10px; font-size: 10px;">test</td></tr></table>'),
|
||||||
defaultHeight,
|
defaultHeight,
|
||||||
newHeight;
|
newHeight;
|
||||||
|
|
||||||
$obj.appendTo('body');
|
$obj.appendTo('body');
|
||||||
|
|
||||||
defaultHeight = $obj.find('td').height();
|
defaultHeight = $obj.find('td').height();
|
||||||
|
|
||||||
$obj.find('td')
|
$obj.find('td')
|
||||||
.css('height', $obj.find('tr').height());
|
.css('height', $obj.find('tr').height());
|
||||||
|
|
||||||
newHeight = $obj.find('td').height();
|
newHeight = $obj.find('td').height();
|
||||||
$obj.remove();
|
$obj.remove();
|
||||||
|
|
||||||
if ( defaultHeight != newHeight ) {
|
if ( defaultHeight != newHeight ) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -614,24 +626,24 @@
|
||||||
var scrollbarWidth = 0;
|
var scrollbarWidth = 0;
|
||||||
|
|
||||||
if ( !scrollbarWidth ) {
|
if ( !scrollbarWidth ) {
|
||||||
if ( $.browser.msie ) {
|
if ( $.browser.msie ) {
|
||||||
var $textarea1 = $('<textarea cols="10" rows="2"></textarea>')
|
var $textarea1 = $('<textarea cols="10" rows="2"></textarea>')
|
||||||
.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body'),
|
.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body'),
|
||||||
$textarea2 = $('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>')
|
$textarea2 = $('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>')
|
||||||
.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body');
|
.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body');
|
||||||
scrollbarWidth = $textarea1.width() - $textarea2.width() + 2; // + 2 for border offset
|
scrollbarWidth = $textarea1.width() - $textarea2.width() + 2; // + 2 for border offset
|
||||||
$textarea1.add($textarea2).remove();
|
$textarea1.add($textarea2).remove();
|
||||||
} else {
|
} else {
|
||||||
var $div = $('<div />')
|
var $div = $('<div />')
|
||||||
.css({ width: 100, height: 100, overflow: 'auto', position: 'absolute', top: -1000, left: -1000 })
|
.css({ width: 100, height: 100, overflow: 'auto', position: 'absolute', top: -1000, left: -1000 })
|
||||||
.prependTo('body').append('<div />').find('div')
|
.prependTo('body').append('<div />').find('div')
|
||||||
.css({ width: '100%', height: 200 });
|
.css({ width: '100%', height: 200 });
|
||||||
scrollbarWidth = 100 - $div.width();
|
scrollbarWidth = 100 - $div.width();
|
||||||
$div.parent().remove();
|
$div.parent().remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return scrollbarWidth;
|
return scrollbarWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -643,13 +655,13 @@
|
||||||
// call the respective method
|
// call the respective method
|
||||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||||
|
|
||||||
// if an object is given as method OR nothing is given as argument
|
// if an object is given as method OR nothing is given as argument
|
||||||
} else if ( typeof method === 'object' || !method ) {
|
} else if ( typeof method === 'object' || !method ) {
|
||||||
|
|
||||||
// call the initialization method
|
// call the initialization method
|
||||||
return methods.init.apply(this, arguments);
|
return methods.init.apply(this, arguments);
|
||||||
|
|
||||||
// otherwise
|
// otherwise
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// trigger an error
|
// trigger an error
|
||||||
|
|
Loading…
Reference in New Issue