diff --git a/jquery.fixedheadertable.js b/jquery.fixedheadertable.js index 3913980..1d052d8 100644 --- a/jquery.fixedheadertable.js +++ b/jquery.fixedheadertable.js @@ -131,7 +131,10 @@ $divHead = $('
').prependTo($wrapper); } - $divHead.find('table.fht-table').addClass(settings.originalTable.attr('class')); + $divHead.find('table.fht-table') + .addClass(settings.originalTable.attr('class')) + .attr('style', settings.originalTable.attr('style')); + $thead.clone().appendTo($divHead.find('table')); } else { $divHead = $wrapper.find('div.fht-thead'); diff --git a/jquery.fixedheadertable.min.js b/jquery.fixedheadertable.min.js index 90e2e97..6c8a9ef 100644 --- a/jquery.fixedheadertable.min.js +++ b/jquery.fixedheadertable.min.js @@ -16,5 +16,5 @@ * * * all CSS sizing (width,height) is done in pixels (px) - */(function(d){d.fn.fixedHeaderTable=function(m){var u={width:"100%",height:"100%",themeClass:"fht-default",borderCollapse:!0,fixedColumns:0,fixedColumn:!1,sortable:!1,autoShow:!0,footer:!1,cloneHeadToFoot:!1,autoResize:!1,create:null},b={},l={init:function(a){b=d.extend({},u,a);return this.each(function(){var a=d(this);h._isTable(a)?(l.setup.apply(this,Array.prototype.slice.call(arguments,1)),d.isFunction(b.create)&&b.create.call(this)):d.error("Invalid table mark-up")})},setup:function(){var a=d(this), c=a.find("thead"),e=a.find("tfoot"),g=0,f,k,n;b.originalTable=d(this).clone();b.includePadding=h._isPaddingIncludedWithWidth();b.scrollbarOffset=h._getScrollbarWidth();b.themeClassName=b.themeClass;f=-1'));f=a.closest(".fht-table-wrapper");!0==b.fixedColumn&&0>=b.fixedColumns&&(b.fixedColumns= 1);0'),d('
').prependTo(f),k=f.find(".fht-fixed-body"));f.css({width:b.width,height:b.height}).addClass(b.themeClassName);a.hasClass("fht-table-init")||a.wrap('
');n=a.closest(".fht-tbody");var p=h._getTableProps(a);h._setupClone(n,p.tbody);a.hasClass("fht-table-init")?k=f.find("div.fht-thead"):(k=0
').prependTo(k): d('
').prependTo(f),k.find("table.fht-table").addClass(b.originalTable.attr("class")),c.clone().appendTo(k.find("table")));h._setupClone(k,p.thead);a.css({"margin-top":-k.outerHeight(!0)});!0==b.footer&&(h._setupTableFooter(a,this,p),e.length||(e=f.find("div.fht-tfoot table")),g=e.outerHeight(!0));c=f.height()-c.outerHeight(!0)-g-p.border;n.css({height:c});a.addClass("fht-table-init");"undefined"!==typeof b.altClass&&l.altRows.apply(this); 0
'),n=d('
');a=d('
'); var g=g.width(),p=f.find(".fht-tbody").height()-b.scrollbarOffset,q,m,l,r;k.find("table.fht-table").addClass(b.originalTable.attr("class"));n.find("table.fht-table").addClass(b.originalTable.attr("class"));a.find("table.fht-table").addClass(b.originalTable.attr("class"));q=f.find(".fht-thead thead tr > *:lt("+b.fixedColumns+")");l=b.fixedColumns*e.border;q.each(function(){l+=d(this).outerWidth(!0)});h._fixHeightWithCss(q,e);h._fixWidthWithCss(q,e);var s=[];q.each(function(){s.push(d(this).width())}); m=f.find("tbody tr > *:not(:nth-child(n+"+(b.fixedColumns+1)+"))").each(function(a){h._fixHeightWithCss(d(this),e);h._fixWidthWithCss(d(this),e,s[a%b.fixedColumns])});k.appendTo(c).find("tr").append(q.clone());n.appendTo(c).css({"margin-top":-1,height:p+e.border});m.each(function(a){0==a%b.fixedColumns&&(r=d("").appendTo(n.find("tbody")),b.altClass&&d(this).parent().hasClass(b.altClass)&&r.addClass(b.altClass));d(this).clone().appendTo(r)});c.css({height:0,width:l});var t=c.find(".fht-tbody .fht-table").height()- c.find(".fht-tbody").height();c.find(".fht-tbody .fht-table").bind("mousewheel",function(a,c,b,e){if(0!=e)return a=parseInt(d(this).css("marginTop"),10)+(0 *:lt("+b.fixedColumns+")"),h._fixHeightWithCss(k,e),a.appendTo(c).find("tr").append(k.clone()),c=a.find("table").innerWidth(),a.css({top:b.scrollbarOffset, width:c})},_setupTableFooter:function(a,c,e){c=a.closest(".fht-table-wrapper");var g=a.find("tfoot");a=c.find("div.fht-tfoot");a.length||(a=0
').appendTo(c.find(".fht-fixed-body")):d('
').appendTo(c));a.find("table.fht-table").addClass(b.originalTable.attr("class"));switch(!0){case !g.length&&!0==b.cloneHeadToFoot&&!0==b.footer:e=c.find("div.fht-thead");a.empty(); e.find("table").clone().appendTo(a);break;case g.length&&!1==b.cloneHeadToFoot&&!0==b.footer:a.find("table").append(g).css({"margin-top":-e.border}),h._setupClone(a,e.tfoot)}},_getTableProps:function(a){var c={thead:{},tbody:{},tfoot:{},border:0},e=1;!0==b.borderCollapse&&(e=2);c.border=(a.find("th:first-child").outerWidth()-a.find("th:first-child").innerWidth())/e;a.find("thead tr:first-child > *").each(function(a){c.thead[a]=d(this).width()+c.border});a.find("tfoot tr:first-child > *").each(function(a){c.tfoot[a]= d(this).width()+c.border});a.find("tbody tr:first-child > *").each(function(a){c.tbody[a]=d(this).width()+c.border});return c},_setupClone:function(a,c){var e=a.find("thead").length?"thead tr:first-child > *":a.find("tfoot").length?"tfoot tr:first-child > *":"tbody tr:first-child > *",g;a.find(e).each(function(a){g=d(this).find("div.fht-cell").length?d(this).find("div.fht-cell"):d('
').appendTo(d(this));g.css({width:parseInt(c[a],10)});d(this).closest(".fht-tbody").length|| !d(this).is(":last-child")||d(this).closest(".fht-fixed-column").length||(a=Math.max((d(this).innerWidth()-d(this).width())/2,b.scrollbarOffset),d(this).css({"padding-right":parseInt(d(this).css("padding-right"))+a+"px"}))})},_isPaddingIncludedWithWidth:function(){var a=d('
test
'),c,e;a.addClass(b.originalTable.attr("class"));a.appendTo("body");c=a.find("td").height();a.find("td").css("height",a.find("tr").height()); e=a.find("td").height();a.remove();return c!=e?!0:!1},_getScrollbarWidth:function(){var a=0;if(!a)if(/msie/.test(navigator.userAgent.toLowerCase())){var c=d('').css({position:"absolute",top:-1E3,left:-1E3}).appendTo("body"),b=d('').css({position:"absolute",top:-1E3,left:-1E3}).appendTo("body"),a=c.width()-b.width()+2;c.add(b).remove()}else c=d("
").css({width:100,height:100,overflow:"auto", position:"absolute",top:-1E3,left:-1E3}).prependTo("body").append("
").find("div").css({width:"100%",height:200}),a=100-c.width(),c.parent().remove();return a}};if(l[m])return l[m].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof m&&m)d.error('Method "'+m+'" does not exist in fixedHeaderTable plugin!');else return l.init.apply(this,arguments)}})(jQuery); + */(function(c){c.fn.fixedHeaderTable=function(m){var u={width:"100%",height:"100%",themeClass:"fht-default",borderCollapse:!0,fixedColumns:0,fixedColumn:!1,sortable:!1,autoShow:!0,footer:!1,cloneHeadToFoot:!1,autoResize:!1,create:null},b={},n={init:function(a){b=c.extend({},u,a);return this.each(function(){var a=c(this);h._isTable(a)?(n.setup.apply(this,Array.prototype.slice.call(arguments,1)),c.isFunction(b.create)&&b.create.call(this)):c.error("Invalid table mark-up")})},setup:function(){var a=c(this), d=a.find("thead"),e=a.find("tfoot"),g=0,f,k,p;b.originalTable=c(this).clone();b.includePadding=h._isPaddingIncludedWithWidth();b.scrollbarOffset=h._getScrollbarWidth();b.themeClassName=b.themeClass;f=-1
'));f=a.closest(".fht-table-wrapper");!0==b.fixedColumn&&0>=b.fixedColumns&&(b.fixedColumns= 1);0
'),c('
').prependTo(f),k=f.find(".fht-fixed-body"));f.css({width:b.width,height:b.height}).addClass(b.themeClassName);a.hasClass("fht-table-init")||a.wrap('
');p=a.closest(".fht-tbody");var l=h._getTableProps(a);h._setupClone(p,l.tbody);a.hasClass("fht-table-init")?k=f.find("div.fht-thead"):(k=0
').prependTo(k): c('
').prependTo(f),k.find("table.fht-table").addClass(b.originalTable.attr("class")).attr("style",b.originalTable.attr("style")),d.clone().appendTo(k.find("table")));h._setupClone(k,l.thead);a.css({"margin-top":-k.outerHeight(!0)});!0==b.footer&&(h._setupTableFooter(a,this,l),e.length||(e=f.find("div.fht-tfoot table")),g=e.outerHeight(!0));d=f.height()-d.outerHeight(!0)-g-l.border;p.css({height:d});a.addClass("fht-table-init");"undefined"!== typeof b.altClass&&n.altRows.apply(this);0
'),p=c('
');a=c('
'); var g=g.width(),l=f.find(".fht-tbody").height()-b.scrollbarOffset,q,t,r,s;k.find("table.fht-table").addClass(b.originalTable.attr("class"));p.find("table.fht-table").addClass(b.originalTable.attr("class"));a.find("table.fht-table").addClass(b.originalTable.attr("class"));q=f.find(".fht-thead thead tr > *:lt("+b.fixedColumns+")");r=b.fixedColumns*e.border;q.each(function(){r+=c(this).outerWidth(!0)});h._fixHeightWithCss(q,e);h._fixWidthWithCss(q,e);var m=[];q.each(function(){m.push(c(this).width())}); t=f.find("tbody tr > *:not(:nth-child(n+"+(b.fixedColumns+1)+"))").each(function(a){h._fixHeightWithCss(c(this),e);h._fixWidthWithCss(c(this),e,m[a%b.fixedColumns])});k.appendTo(d).find("tr").append(q.clone());p.appendTo(d).css({"margin-top":-1,height:l+e.border});t.each(function(a){0==a%b.fixedColumns&&(s=c("").appendTo(p.find("tbody")),b.altClass&&c(this).parent().hasClass(b.altClass)&&s.addClass(b.altClass));c(this).clone().appendTo(s)});d.css({height:0,width:r});var n=d.find(".fht-tbody .fht-table").height()- d.find(".fht-tbody").height();d.find(".fht-tbody .fht-table").bind("mousewheel",function(a,d,b,e){if(0!=e)return a=parseInt(c(this).css("marginTop"),10)+(0 *:lt("+b.fixedColumns+")"),h._fixHeightWithCss(k,e),a.appendTo(d).find("tr").append(k.clone()),d=a.find("table").innerWidth(),a.css({top:b.scrollbarOffset, width:d})},_setupTableFooter:function(a,d,e){d=a.closest(".fht-table-wrapper");var g=a.find("tfoot");a=d.find("div.fht-tfoot");a.length||(a=0
').appendTo(d.find(".fht-fixed-body")):c('
').appendTo(d));a.find("table.fht-table").addClass(b.originalTable.attr("class"));switch(!0){case !g.length&&!0==b.cloneHeadToFoot&&!0==b.footer:e=d.find("div.fht-thead");a.empty(); e.find("table").clone().appendTo(a);break;case g.length&&!1==b.cloneHeadToFoot&&!0==b.footer:a.find("table").append(g).css({"margin-top":-e.border}),h._setupClone(a,e.tfoot)}},_getTableProps:function(a){var d={thead:{},tbody:{},tfoot:{},border:0},c=1;!0==b.borderCollapse&&(c=2);d.border=(a.find("th:first-child").outerWidth()-a.find("th:first-child").innerWidth())/c;d.thead=h._getColumnsWidth(a.find("thead tr"));d.tfoot=h._getColumnsWidth(a.find("tfoot tr"));d.tbody=h._getColumnsWidth(a.find("tbody tr")); return d},_getColumnsWidth:function(a){var d={},b={},g=0,f,k;f=h._getColumnsCount(a);for(k=0;k').appendTo(c(this))).css({width:parseInt(d[a].width,10)}),c(this).closest(".fht-tbody").length||!c(this).is(":last-child")||c(this).closest(".fht-fixed-column").length|| (a=Math.max((c(this).innerWidth()-c(this).width())/2,b.scrollbarOffset),c(this).css({"padding-right":parseInt(c(this).css("padding-right"))+a+"px"})))})})},_isPaddingIncludedWithWidth:function(){var a=c('
test
'),d,e;a.addClass(b.originalTable.attr("class"));a.appendTo("body");d=a.find("td").height();a.find("td").css("height",a.find("tr").height());e=a.find("td").height();a.remove();return d!=e?!0:!1},_getScrollbarWidth:function(){var a= 0;if(!a)if(/msie/.test(navigator.userAgent.toLowerCase())){var b=c('').css({position:"absolute",top:-1E3,left:-1E3}).appendTo("body"),e=c('').css({position:"absolute",top:-1E3,left:-1E3}).appendTo("body"),a=b.width()-e.width()+2;b.add(e).remove()}else b=c("
").css({width:100,height:100,overflow:"auto",position:"absolute",top:-1E3,left:-1E3}).prependTo("body").append("
").find("div").css({width:"100%", height:200}),a=100-b.width(),b.parent().remove();return a}};if(n[m])return n[m].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof m&&m)c.error('Method "'+m+'" does not exist in fixedHeaderTable plugin!');else return n.init.apply(this,arguments)}})(jQuery);