2016-09-23 16:45:10 +00:00
|
|
|
/*! Widget: repeatHeaders - updated 9/23/2016 (v2.27.7) *//*
|
2013-04-12 22:14:00 +00:00
|
|
|
* Requires tablesorter v2.8+ and jQuery 1.7+
|
|
|
|
* Original by Christian Bach from the example-widgets.html demo
|
|
|
|
*/
|
|
|
|
/*global jQuery: false */
|
2018-03-17 20:30:25 +00:00
|
|
|
;(function($) {
|
2015-02-02 01:37:12 +00:00
|
|
|
'use strict';
|
2013-04-12 22:14:00 +00:00
|
|
|
|
|
|
|
$.tablesorter.addWidget({
|
2015-02-02 01:37:12 +00:00
|
|
|
id: 'repeatHeaders',
|
2013-04-12 22:14:00 +00:00
|
|
|
priority: 10,
|
|
|
|
options: {
|
|
|
|
rowsToSkip : 4
|
|
|
|
},
|
|
|
|
// format is called on init and when a sorting has finished
|
|
|
|
format: function(table, c, wo) {
|
|
|
|
var h = '', i, $tr, l, skip;
|
|
|
|
// cache and collect all TH headers
|
|
|
|
if (!wo.repeatHeaders) {
|
2015-05-24 15:44:52 +00:00
|
|
|
h = '<tr class="repeated-header ' + c.selectorRemove.slice(1) + '">';
|
2015-02-02 01:37:12 +00:00
|
|
|
for (i = 0; i < c.columns; i++) {
|
2016-09-06 08:14:00 +00:00
|
|
|
// repeat the content of the current header (including child elements)
|
|
|
|
h += '<th>' + $.trim( c.$headers.eq(i).html() ) + '</th>';
|
2015-02-02 01:37:12 +00:00
|
|
|
}
|
|
|
|
// '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
|
2013-04-12 22:14:00 +00:00
|
|
|
wo.repeatHeaders = h + '</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// number of rows to skip
|
|
|
|
skip = wo && wo.rowsToSkip || 4;
|
|
|
|
|
|
|
|
// remove appended headers by classname
|
2015-02-02 01:37:12 +00:00
|
|
|
c.$table.find('tr.repeated-header').remove();
|
2013-04-12 22:14:00 +00:00
|
|
|
$tr = c.$tbodies.find('tr');
|
|
|
|
l = $tr.length;
|
2015-02-02 01:37:12 +00:00
|
|
|
// loop all tr elements and insert a copy of the 'headers'
|
2013-04-12 22:14:00 +00:00
|
|
|
for (i = skip; i < l; i += skip) {
|
|
|
|
// insert a copy of the table head every X rows
|
|
|
|
$tr.eq(i).before(wo.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+
|
2018-03-17 20:30:25 +00:00
|
|
|
remove: function(table, c, wo) {
|
2015-02-02 01:37:12 +00:00
|
|
|
wo.repeatHeaders = '';
|
|
|
|
c.$table.find('tr.repeated-header').remove();
|
2013-04-12 22:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|