2017-05-24 23:53:44 +00:00
|
|
|
/*! Widget: columns - updated 5/24/2017 (v2.28.11) */
|
2015-02-13 03:10:38 +00:00
|
|
|
;(function ($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
|
|
|
var ts = $.tablesorter || {};
|
2015-02-13 03:10:38 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
ts.addWidget({
|
|
|
|
id: 'columns',
|
2017-05-23 23:06:42 +00:00
|
|
|
priority: 65,
|
2015-07-23 04:29:51 +00:00
|
|
|
options : {
|
|
|
|
columns : [ 'primary', 'secondary', 'tertiary' ]
|
|
|
|
},
|
|
|
|
format: function(table, c, wo) {
|
|
|
|
var $tbody, tbodyIndex, $rows, rows, $row, $cells, remove, indx,
|
2015-02-13 03:10:38 +00:00
|
|
|
$table = c.$table,
|
|
|
|
$tbodies = c.$tbodies,
|
|
|
|
sortList = c.sortList,
|
|
|
|
len = sortList.length,
|
|
|
|
// removed c.widgetColumns support
|
2015-07-23 04:29:51 +00:00
|
|
|
css = wo && wo.columns || [ 'primary', 'secondary', 'tertiary' ],
|
2015-02-13 03:10:38 +00:00
|
|
|
last = css.length - 1;
|
|
|
|
remove = css.join(' ');
|
2015-07-23 04:29:51 +00:00
|
|
|
// check if there is a sort (on initialization there may not be one)
|
|
|
|
for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
|
|
|
|
$tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); // detach tbody
|
|
|
|
$rows = $tbody.children('tr');
|
|
|
|
// loop through the visible rows
|
|
|
|
$rows.each(function() {
|
|
|
|
$row = $(this);
|
|
|
|
if (this.style.display !== 'none') {
|
|
|
|
// remove all columns class names
|
|
|
|
$cells = $row.children().removeClass(remove);
|
|
|
|
// add appropriate column class names
|
|
|
|
if (sortList && sortList[0]) {
|
|
|
|
// primary sort column class
|
|
|
|
$cells.eq(sortList[0][0]).addClass(css[0]);
|
|
|
|
if (len > 1) {
|
|
|
|
for (indx = 1; indx < len; indx++) {
|
|
|
|
// secondary, tertiary, etc sort column classes
|
|
|
|
$cells.eq(sortList[indx][0]).addClass( css[indx] || css[last] );
|
|
|
|
}
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
ts.processTbody(table, $tbody, false);
|
|
|
|
}
|
|
|
|
// add classes to thead and tfoot
|
|
|
|
rows = wo.columns_thead !== false ? [ 'thead tr' ] : [];
|
|
|
|
if (wo.columns_tfoot !== false) {
|
|
|
|
rows.push('tfoot tr');
|
|
|
|
}
|
|
|
|
if (rows.length) {
|
|
|
|
$rows = $table.find( rows.join(',') ).children().removeClass(remove);
|
|
|
|
if (len) {
|
|
|
|
for (indx = 0; indx < len; indx++) {
|
|
|
|
// add primary. secondary, tertiary, etc sort column classes
|
|
|
|
$rows.filter('[data-column="' + sortList[indx][0] + '"]').addClass(css[indx] || css[last]);
|
|
|
|
}
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
remove: function(table, c, wo) {
|
|
|
|
var tbodyIndex, $tbody,
|
|
|
|
$tbodies = c.$tbodies,
|
|
|
|
remove = (wo.columns || [ 'primary', 'secondary', 'tertiary' ]).join(' ');
|
|
|
|
c.$headers.removeClass(remove);
|
|
|
|
c.$table.children('tfoot').children('tr').children('th, td').removeClass(remove);
|
|
|
|
for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
|
|
|
|
$tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true); // remove tbody
|
|
|
|
$tbody.children('tr').each(function() {
|
|
|
|
$(this).children().removeClass(remove);
|
|
|
|
});
|
|
|
|
ts.processTbody(table, $tbody, false); // restore tbody
|
|
|
|
}
|
2015-02-13 03:10:38 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
2015-02-13 03:10:38 +00:00
|
|
|
|
|
|
|
})(jQuery);
|