Fixed-Header-Table/jquery.fixedheadertable.min.js

19 lines
10 KiB
JavaScript
Raw Permalink Normal View History

/*
* jquery.fixedHeaderTable. The jQuery fixedHeaderTable plugin
*
* Copyright (c) 2013 Mark Malek
* (c) 2015-2016 Vitaliy Filippov
* http://fixedheadertable.com
*
* Licensed under MIT
* http://www.opensource.org/licenses/mit-license.php
*
* http://docs.jquery.com/Plugins/Authoring
* jQuery authoring guidelines
*
* Version: 2016-08-10
* Based on: Original 1.3 (2011-05-09)
*
* all CSS sizing (width,height) is done in pixels (px)
*/
(function(a){a.fn.fixedHeaderTable=function(f){var e={width:"100%",height:"100%",themeClass:"fht-default",borderCollapse:true,fixedColumns:0,fixedColumn:false,sortable:false,autoShow:true,footer:false,cloneHeadToFoot:false,autoResize:true,create:null};var c={};var b={init:function(g){c=a.extend({},e,g);return this.each(function(){var h=a(this);if(d._isTable(h)){b.setup.apply(this,Array.prototype.slice.call(arguments,1));a.isFunction(c.create)&&c.create.call(this)}else{a.error("Invalid table mark-up")}})},setup:function(){var r=a(this),s=this,m=r.find("thead"),p=r.find("tfoot"),n=0,k,o,j,i,g,q;c.originalTable=a(this).clone();c.includePadding=d._isPaddingIncludedWithWidth();c.scrollbarOffset=d._getScrollbarWidth();c.themeClassName=c.themeClass;if(c.width.search("%")>-1){g=r.parent().width()}else{g=c.width}q=g-c.scrollbarOffset;r.css({width:q});if(!r.closest(".fht-table-wrapper").length){r.addClass("fht-table");r.wrap('<div class="fht-table-wrapper"></div>')}k=r.closest(".fht-table-wrapper");if(c.fixedColumn==true&&c.fixedColumns<=0){c.fixedColumns=1}if(c.fixedColumns>0&&k.find(".fht-fixed-column").length==0){r.wrap('<div class="fht-fixed-body"></div>');a('<div class="fht-fixed-column"></div>').prependTo(k);i=k.find(".fht-fixed-body")}k.css({width:c.width,height:c.height}).addClass(c.themeClassName);if(!r.hasClass("fht-table-init")){r.wrap('<div class="fht-tbody"></div>')}j=r.closest(".fht-tbody");var h=d._getTableProps(r);d._setupClone(j,h.thead);if(!r.hasClass("fht-table-init")){if(c.fixedColumns>0){o=a('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo(i)}else{o=a('<div class="fht-thead"><table class="fht-table"></table></div>').prependTo(k)}o.find("table.fht-table").addClass(c.originalTable.attr("class")).attr("style",c.originalTable.attr("style"));m.clone().appendTo(o.find("table"))}else{o=k.find(c.fixedColumns>0?"div.fht-fixed-body div.fht-thead":"div.fht-thead");o.find("thead").remove();m.clone().appendTo(o.find("table"))}o.find("table.fht-table").css({width:g});if(c.footer==true){d._setupTableFooter(r,s,h);if(!p.length){p=k.find("div.fht-tfoot table")}n=p.outerHeight(true)}var l=k.height()-m.outerHeight(true)-n-h.border;if(r.height()-o.outerHeight(true)<=l){o.find("table.fht-table").css({width:q});c.scrollbarOffset=0}d._setupClone(o,h.thead);r.css({"margin-top":-o.outerHeight(true)});j.css({height:l});if(c.autoResize&&!r.hasClass("fht-table-init")){a(window).on("resize",function(){k.find(".fht-cell").remove();r.fixedHeaderTable(c);b.resize.apply(s)})}r.addClass("fht-table-init");if(typeof(c.altClass)!=="undefined"){b.altRows.apply(s)}if(c.fixedColumns>0){d._setupFixedColumn(r,s,h)}if(!c.autoShow){k.hide()}d._bindScroll(j,h);return s},resize:function(){var g=a(this);g.closest(".fht-table-wrapper").find(".fht-cell").remove();g.fixedHeaderTable();return self},altRows:function(h){var i=a(this),g=(typeof(h)!=="undefined")?h:c.altClass;i.closest(".fht-table-wrapper").find("tbody tr:odd:not(:hidden)").addClass(g)},show:function(j,i,g){var l=a(this),h=this,k=l.closest(".fht-table-wrapper");if(typeof(j)!=="undefined"&&typeof(j)==="number"){k.show(j,function(){a.isFunction(i)&&i.call(this)});return h}else{if(typeof(j)!=="undefined"&&typeof(j)==="string"&&typeof(i)!=="undefined"&&typeof(i)==="number"){k.show(j,i,function(){a.isFunction(g)&&g.call(this)});return h}}l.closest(".fht-table-wrapper").show();a.isFunction(j)&&j.call(this);return h},hide:function(j,i,g){var l=a(this),h=this,k=l.closest(".fht-table-wrapper");if(typeof(j)!=="undefined"&&typeof(j)==="number"){k.hide(j,function(){a.isFunction(g)&&g.call(this)});return h}else{if(typeof(j)!=="undefined"&&typeof(j)==="string"&&typeof(i)!=="undefined"&&typeof(i)==="number"){k.hide(j,i,function(){a.isFunction(g)&&g.call(this)});return h}}l.closest(".fht-table-wrapper").hide();a.isFunction(g)&&g.call(this);return h},destroy:function(){var i=a(this),g=this,h=i.closest(".fht-table-wrapper");i.insertBefore(h).removeAttr("style").append(h.find("tfoot")).removeClass("fht-table fht-table-init").find(".fht-cell").remove();h.remove();return g}};var d={_isTable