tablesorter/dist/js/widgets/widget-repeatheaders.min.js

23 lines
1.4 KiB
JavaScript
Raw Normal View History

/*! Widget: repeatHeaders - updated 2/7/2015 (v2.19.0) */
2015-10-31 15:08:21 +00:00
/*
* Requires tablesorter v2.8+ and jQuery 1.7+
* Original by Christian Bach from the example-widgets.html demo
*/
/*global jQuery: false */
!function(a){"use strict";a.tablesorter.addWidget({id:"repeatHeaders",priority:10,options:{rowsToSkip:4},
// format is called on init and when a sorting has finished
format:function(b,c,d){var e,f,g,h,i="";
// cache and collect all TH headers
if(!d.repeatHeaders){for(i='<tr class="repeated-header '+c.selectorRemove.slice(1)+'">',e=0;e<c.columns;e++)
// only get the headerContent text
i+="<th>"+a.trim(c.$headers.eq(e).text())+"</th>";
// 'remove-me' class was added in case the table needs to be updated, the 'remove-me' rows will be
// removed prior to the update to prevent including the rows in the update - see 'selectorRemove' option
d.repeatHeaders=i+"</tr>"}
// loop all tr elements and insert a copy of the 'headers'
for(h=d&&d.rowsToSkip||4,c.$table.find("tr.repeated-header").remove(),f=c.$tbodies.find("tr"),g=f.length,e=h;g>e;e+=h)
// insert a copy of the table head every X rows
f.eq(e).before(d.repeatHeaders)},
// this remove function is called when using the refreshWidgets method or when destroying the tablesorter plugin
// this function only applies to tablesorter v2.4+
remove:function(a,b,c){c.repeatHeaders="",b.$table.find("tr.repeated-header").remove()}})}(jQuery);