2017-07-04 16:59:53 +00:00
|
|
|
/* Widget: columnSelector (responsive table widget) - updated 7/4/2017 (v2.28.15) *//*
|
2013-12-17 23:39:39 +00:00
|
|
|
* Requires tablesorter v2.8+ and jQuery 1.7+
|
|
|
|
* by Justin Hallett & Rob Garrison
|
|
|
|
*/
|
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
|
|
|
/*global jQuery: false */
|
|
|
|
;(function($){
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
var ts = $.tablesorter,
|
|
|
|
namespace = '.tscolsel',
|
|
|
|
tsColSel = ts.columnSelector = {
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
queryAll : '@media only all { [columns] { display: none; } } ',
|
|
|
|
queryBreak : '@media all and (min-width: [size]) { [columns] { display: table-cell; } } ',
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
init: function(table, c, wo) {
|
|
|
|
var $t, colSel;
|
2014-02-06 04:20:25 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// abort if no input is contained within the layout
|
|
|
|
$t = $(wo.columnSelector_layout);
|
|
|
|
if (!$t.find('input').add( $t.filter('input') ).length) {
|
|
|
|
if (c.debug) {
|
2015-07-24 23:23:00 +00:00
|
|
|
console.error('ColumnSelector: >> ERROR: Column Selector aborting, no input found in the layout! ***');
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
return;
|
2014-02-06 04:20:25 +00:00
|
|
|
}
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// unique table class name
|
|
|
|
c.$table.addClass( c.namespace.slice(1) + 'columnselector' );
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// build column selector/state array
|
|
|
|
colSel = c.selector = { $container : $(wo.columnSelector_container || '<div>') };
|
|
|
|
colSel.$style = $('<style></style>').prop('disabled', true).appendTo('head');
|
|
|
|
colSel.$breakpoints = $('<style></style>').prop('disabled', true).appendTo('head');
|
2014-03-10 01:20:17 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
colSel.isInitializing = true;
|
2015-10-27 16:45:43 +00:00
|
|
|
tsColSel.setUpColspan(c, wo);
|
2015-08-17 03:46:22 +00:00
|
|
|
tsColSel.setupSelector(c, wo);
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
if (wo.columnSelector_mediaquery) {
|
|
|
|
tsColSel.setupBreakpoints(c, wo);
|
|
|
|
}
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
colSel.isInitializing = false;
|
|
|
|
if (colSel.$container.length) {
|
|
|
|
tsColSel.updateCols(c, wo);
|
|
|
|
} else if (c.debug) {
|
2015-07-24 23:23:00 +00:00
|
|
|
console.warn('ColumnSelector: >> container not found');
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
c.$table
|
|
|
|
.off('refreshColumnSelector' + namespace)
|
2015-08-17 03:46:22 +00:00
|
|
|
/* $('table').trigger('refreshColumnSelector', arguments ); showing arguments below
|
|
|
|
undefined = refresh current settings (update css hiding columns)
|
|
|
|
'selectors' = update container contents (replace inputs/labels)
|
|
|
|
[ [2,3,4] ] = set visible columns; turn off "auto" mode.
|
|
|
|
[ 'columns', [2,3,4] ] = set visible columns; turn off "auto" mode.
|
|
|
|
[ 'auto', [2,3,4] ] = set visible columns; turn on "auto" mode.
|
|
|
|
true = turn on "auto" mode.
|
|
|
|
*/
|
|
|
|
.on('refreshColumnSelector' + namespace, function( e, optName, optState ){
|
2015-07-23 04:29:51 +00:00
|
|
|
// make sure we're using current config settings
|
2015-08-17 03:46:22 +00:00
|
|
|
tsColSel.refreshColumns( this.config, optName, optState );
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-08-17 03:46:22 +00:00
|
|
|
refreshColumns: function( c, optName, optState ) {
|
2016-04-30 00:47:41 +00:00
|
|
|
var i, arry, $el, val,
|
|
|
|
colSel = c.selector,
|
2015-08-17 03:46:22 +00:00
|
|
|
isArry = $.isArray(optState || optName),
|
|
|
|
wo = c.widgetOptions;
|
|
|
|
// see #798
|
2016-07-28 20:36:55 +00:00
|
|
|
if (typeof optName !== 'undefined' && optName !== null && colSel.$container.length) {
|
2015-08-17 03:46:22 +00:00
|
|
|
// pass "selectors" to update the all of the container contents
|
|
|
|
if ( optName === 'selectors' ) {
|
2016-04-30 00:47:41 +00:00
|
|
|
colSel.$container.empty();
|
2015-08-17 03:46:22 +00:00
|
|
|
tsColSel.setupSelector(c, wo);
|
|
|
|
tsColSel.setupBreakpoints(c, wo);
|
|
|
|
// if optState is undefined, maintain the current "auto" state
|
2016-08-01 02:08:48 +00:00
|
|
|
if ( typeof optState === 'undefined' && optState !== null ) {
|
2016-04-30 00:47:41 +00:00
|
|
|
optState = colSel.auto;
|
2015-08-17 03:46:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// pass an array of column zero-based indexes to turn off auto mode & toggle selected columns
|
|
|
|
if (isArry) {
|
|
|
|
arry = optState || optName;
|
|
|
|
// make sure array contains numbers
|
|
|
|
$.each(arry, function(i, v){
|
|
|
|
arry[i] = parseInt(v, 10);
|
|
|
|
});
|
|
|
|
for (i = 0; i < c.columns; i++) {
|
2016-04-30 00:47:41 +00:00
|
|
|
val = $.inArray( i, arry ) >= 0;
|
|
|
|
$el = colSel.$container.find( 'input[data-column=' + i + ']' );
|
|
|
|
if ( $el.length ) {
|
|
|
|
$el.prop( 'checked', val );
|
|
|
|
colSel.states[i] = val;
|
|
|
|
}
|
2015-08-17 03:46:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// if passing an array, set auto to false to allow manual column selection & update columns
|
|
|
|
// refreshColumns( c, 'auto', true ) === refreshColumns( c, true );
|
2016-04-30 00:47:41 +00:00
|
|
|
val = optState === true || optName === true || optName === 'auto' && optState !== false;
|
|
|
|
$el = colSel.$container.find( 'input[data-column="auto"]' ).prop( 'checked', val );
|
|
|
|
tsColSel.updateAuto( c, wo, $el );
|
2015-08-17 03:46:22 +00:00
|
|
|
} else {
|
|
|
|
tsColSel.updateBreakpoints(c, wo);
|
|
|
|
tsColSel.updateCols(c, wo);
|
|
|
|
}
|
2016-04-30 00:47:41 +00:00
|
|
|
tsColSel.saveValues( c, wo );
|
2015-10-27 16:45:43 +00:00
|
|
|
tsColSel.adjustColspans( c, wo );
|
2015-08-17 03:46:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setupSelector: function(c, wo) {
|
2016-12-14 21:43:30 +00:00
|
|
|
var index, name, $header, priority, col, colId, $el,
|
2015-07-23 04:29:51 +00:00
|
|
|
colSel = c.selector,
|
|
|
|
$container = colSel.$container,
|
|
|
|
useStorage = wo.columnSelector_saveColumns && ts.storage,
|
|
|
|
// get stored column states
|
2015-08-17 03:46:22 +00:00
|
|
|
saved = useStorage ? ts.storage( c.table, 'tablesorter-columnSelector' ) : [],
|
|
|
|
state = useStorage ? ts.storage( c.table, 'tablesorter-columnSelector-auto') : {};
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// initial states
|
|
|
|
colSel.auto = $.isEmptyObject(state) || $.type(state.auto) !== 'boolean' ? wo.columnSelector_mediaqueryState : state.auto;
|
|
|
|
colSel.states = [];
|
|
|
|
colSel.$column = [];
|
|
|
|
colSel.$wrapper = [];
|
|
|
|
colSel.$checkbox = [];
|
|
|
|
// populate the selector container
|
2015-10-27 16:45:43 +00:00
|
|
|
for ( index = 0; index < c.columns; index++ ) {
|
2015-10-30 20:28:32 +00:00
|
|
|
$header = c.$headerIndexed[ index ];
|
|
|
|
// if no data-priority is assigned, default to 1, but don't remove it from the selector list
|
|
|
|
priority = $header.attr(wo.columnSelector_priority) || 1;
|
|
|
|
colId = $header.attr('data-column');
|
|
|
|
col = ts.getColumnData( c.table, c.headers, colId );
|
|
|
|
state = ts.getData( $header, col, 'columnSelector');
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// if this column not hidable at all
|
|
|
|
// include getData check (includes 'columnSelector-false' class, data attribute, etc)
|
|
|
|
if ( isNaN(priority) && priority.length > 0 || state === 'disable' ||
|
|
|
|
( wo.columnSelector_columns[colId] && wo.columnSelector_columns[colId] === 'disable') ) {
|
2016-07-28 20:36:55 +00:00
|
|
|
colSel.states[colId] = null;
|
2015-10-27 16:45:43 +00:00
|
|
|
continue; // goto next
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set default state; storage takes priority
|
2016-07-28 20:43:57 +00:00
|
|
|
colSel.states[colId] = saved && (typeof saved[colId] !== 'undefined' && saved[colId] !== null) ?
|
2016-07-28 20:46:58 +00:00
|
|
|
saved[colId] : (typeof wo.columnSelector_columns[colId] !== 'undefined' && wo.columnSelector_columns[colId] !== null) ?
|
2015-07-23 04:29:51 +00:00
|
|
|
wo.columnSelector_columns[colId] : (state === 'true' || state !== 'false');
|
|
|
|
colSel.$column[colId] = $(this);
|
|
|
|
if ($container.length) {
|
2016-12-14 21:43:30 +00:00
|
|
|
// set default col title
|
|
|
|
name = $header.attr(wo.columnSelector_name) || $header.text().trim();
|
2017-01-07 02:56:05 +00:00
|
|
|
if (typeof wo.columnSelector_layoutCustomizer === 'function') {
|
2016-12-14 21:43:30 +00:00
|
|
|
$el = $header.find('.' + ts.css.headerIn);
|
|
|
|
name = wo.columnSelector_layoutCustomizer( $el.length ? $el : $header, name, parseInt(colId, 10) );
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
colSel.$wrapper[colId] = $(wo.columnSelector_layout.replace(/\{name\}/g, name)).appendTo($container);
|
|
|
|
colSel.$checkbox[colId] = colSel.$wrapper[colId]
|
|
|
|
// input may not be wrapped within the layout template
|
|
|
|
.find('input').add( colSel.$wrapper[colId].filter('input') )
|
|
|
|
.attr('data-column', colId)
|
|
|
|
.toggleClass( wo.columnSelector_cssChecked, colSel.states[colId] )
|
|
|
|
.prop('checked', colSel.states[colId])
|
2016-07-21 02:06:52 +00:00
|
|
|
.on('change', function() {
|
|
|
|
if (!colSel.isInitializing) {
|
|
|
|
// ensure states is accurate
|
|
|
|
var colId = $(this).attr('data-column');
|
|
|
|
if (tsColSel.checkChange(c, this.checked)) {
|
|
|
|
// if (wo.columnSelector_maxVisible)
|
|
|
|
c.selector.states[colId] = this.checked;
|
|
|
|
tsColSel.updateCols(c, wo);
|
|
|
|
} else {
|
|
|
|
this.checked = !this.checked;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
}).change();
|
2015-01-20 16:51:17 +00:00
|
|
|
}
|
2015-10-27 16:45:43 +00:00
|
|
|
}
|
2014-05-21 01:47:55 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2016-07-21 02:06:52 +00:00
|
|
|
checkChange: function(c, checked) {
|
|
|
|
var wo = c.widgetOptions,
|
|
|
|
max = wo.columnSelector_maxVisible,
|
|
|
|
min = wo.columnSelector_minVisible,
|
|
|
|
states = c.selector.states,
|
|
|
|
indx = states.length,
|
|
|
|
count = 0;
|
|
|
|
while (indx-- >= 0) {
|
|
|
|
if (states[indx]) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((checked & max !== null && count >= max) ||
|
|
|
|
(!checked && min !== null && count <= min)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2015-10-27 16:45:43 +00:00
|
|
|
setupBreakpoints: function(c, wo) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var colSel = c.selector;
|
2013-12-17 23:39:39 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// add responsive breakpoints
|
|
|
|
if (wo.columnSelector_mediaquery) {
|
|
|
|
// used by window resize function
|
|
|
|
colSel.lastIndex = -1;
|
|
|
|
tsColSel.updateBreakpoints(c, wo);
|
|
|
|
c.$table
|
|
|
|
.off('updateAll' + namespace)
|
2016-09-24 03:45:21 +00:00
|
|
|
.on('updateAll' + namespace, function() {
|
|
|
|
tsColSel.setupSelector(c, wo);
|
|
|
|
tsColSel.setupBreakpoints(c, wo);
|
2015-07-23 04:29:51 +00:00
|
|
|
tsColSel.updateBreakpoints(c, wo);
|
2013-12-17 23:39:39 +00:00
|
|
|
tsColSel.updateCols(c, wo);
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
2013-12-17 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
if (colSel.$container.length) {
|
|
|
|
// Add media queries toggle
|
|
|
|
if (wo.columnSelector_mediaquery) {
|
|
|
|
colSel.$auto = $( wo.columnSelector_layout.replace(/\{name\}/g, wo.columnSelector_mediaqueryName) ).prependTo(colSel.$container);
|
|
|
|
colSel.$auto
|
|
|
|
// needed in case the input in the layout is not wrapped
|
|
|
|
.find('input').add( colSel.$auto.filter('input') )
|
|
|
|
.attr('data-column', 'auto')
|
|
|
|
.prop('checked', colSel.auto)
|
|
|
|
.toggleClass( wo.columnSelector_cssChecked, colSel.auto )
|
|
|
|
.on('change', function(){
|
|
|
|
tsColSel.updateAuto(c, wo, $(this));
|
|
|
|
}).change();
|
|
|
|
}
|
|
|
|
// Add a bind on update to re-run col setup
|
|
|
|
c.$table.off('update' + namespace).on('update' + namespace, function() {
|
2014-05-18 18:14:48 +00:00
|
|
|
tsColSel.updateCols(c, wo);
|
|
|
|
});
|
2013-12-17 23:39:39 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateAuto: function(c, wo, $el) {
|
|
|
|
var colSel = c.selector;
|
|
|
|
colSel.auto = $el.prop('checked') || false;
|
|
|
|
$.each( colSel.$checkbox, function(i, $cb){
|
|
|
|
if ($cb) {
|
|
|
|
$cb[0].disabled = colSel.auto;
|
|
|
|
colSel.$wrapper[i].toggleClass('disabled', colSel.auto);
|
|
|
|
}
|
2013-12-17 23:39:39 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
if (wo.columnSelector_mediaquery) {
|
|
|
|
tsColSel.updateBreakpoints(c, wo);
|
2015-01-20 16:51:17 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
tsColSel.updateCols(c, wo);
|
|
|
|
// copy the column selector to a popup/tooltip
|
|
|
|
if (c.selector.$popup) {
|
|
|
|
c.selector.$popup.find('.tablesorter-column-selector')
|
|
|
|
.html( colSel.$container.html() )
|
|
|
|
.find('input').each(function(){
|
|
|
|
var indx = $(this).attr('data-column');
|
|
|
|
$(this).prop( 'checked', indx === 'auto' ? colSel.auto : colSel.states[indx] );
|
|
|
|
});
|
|
|
|
}
|
2016-04-30 00:47:41 +00:00
|
|
|
tsColSel.saveValues( c, wo );
|
2015-10-27 16:45:43 +00:00
|
|
|
tsColSel.adjustColspans( c, wo );
|
2015-07-23 04:29:51 +00:00
|
|
|
// trigger columnUpdate if auto is true (it gets skipped in updateCols()
|
|
|
|
if (colSel.auto) {
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler(wo.columnSelector_updated);
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
2015-10-19 16:49:21 +00:00
|
|
|
addSelectors: function( prefix, column ) {
|
|
|
|
var array = [],
|
|
|
|
temp = ' col:nth-child(' + column + ')';
|
|
|
|
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp);
|
2016-12-13 17:08:17 +00:00
|
|
|
temp = ' tr:not(.hasSpan) th[data-column="' + ( column - 1 ) + '"]';
|
2015-10-19 16:49:21 +00:00
|
|
|
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp);
|
2016-01-11 02:03:29 +00:00
|
|
|
temp = ' tr:not(.hasSpan) td:nth-child(' + column + ')';
|
|
|
|
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp);
|
|
|
|
// for other cells in colspan columns
|
|
|
|
temp = ' tr td:not(' + prefix + 'HasSpan)[data-column="' + (column - 1) + '"]';
|
2015-10-19 16:49:21 +00:00
|
|
|
array.push(prefix + temp + ',' + prefix + '_extra_table' + temp);
|
|
|
|
return array;
|
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
updateBreakpoints: function(c, wo) {
|
2015-10-19 16:49:21 +00:00
|
|
|
var priority, col, column, breaks,
|
|
|
|
isHidden = [],
|
2015-07-23 04:29:51 +00:00
|
|
|
colSel = c.selector,
|
|
|
|
prefix = c.namespace + 'columnselector',
|
|
|
|
mediaAll = [],
|
|
|
|
breakpts = '';
|
|
|
|
if (wo.columnSelector_mediaquery && !colSel.auto) {
|
|
|
|
colSel.$breakpoints.prop('disabled', true);
|
|
|
|
colSel.$style.prop('disabled', false);
|
|
|
|
return;
|
|
|
|
}
|
2015-10-19 16:49:21 +00:00
|
|
|
if (wo.columnSelector_mediaqueryHidden) {
|
|
|
|
// add columns to be hidden; even when "auto" is set - see #964
|
|
|
|
for ( column = 0; column < c.columns; column++ ) {
|
|
|
|
col = ts.getColumnData( c.table, c.headers, column );
|
|
|
|
isHidden[ column + 1 ] = ts.getData( c.$headerIndexed[ column ], col, 'columnSelector' ) === 'false';
|
|
|
|
if ( isHidden[ column + 1 ] ) {
|
|
|
|
// hide columnSelector false column (in auto mode)
|
|
|
|
mediaAll = mediaAll.concat( tsColSel.addSelectors( prefix, column + 1 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
// only 6 breakpoints (same as jQuery Mobile)
|
2016-04-30 02:08:29 +00:00
|
|
|
for (priority = 0; priority < wo.columnSelector_maxPriorities; priority++){
|
2015-07-23 04:29:51 +00:00
|
|
|
/*jshint loopfunc:true */
|
|
|
|
breaks = [];
|
|
|
|
c.$headers.filter('[' + wo.columnSelector_priority + '=' + (priority + 1) + ']').each(function(){
|
|
|
|
column = parseInt($(this).attr('data-column'), 10) + 1;
|
2015-10-19 16:49:21 +00:00
|
|
|
// don't reveal columnSelector false columns
|
|
|
|
if ( !isHidden[ column ] ) {
|
|
|
|
breaks = breaks.concat( tsColSel.addSelectors( prefix, column ) );
|
|
|
|
}
|
2015-01-20 16:51:17 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
if (breaks.length) {
|
|
|
|
mediaAll = mediaAll.concat( breaks );
|
|
|
|
breakpts += tsColSel.queryBreak
|
|
|
|
.replace(/\[size\]/g, wo.columnSelector_breakpoints[priority])
|
|
|
|
.replace(/\[columns\]/g, breaks.join(','));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (colSel.$style) {
|
|
|
|
colSel.$style.prop('disabled', true);
|
|
|
|
}
|
|
|
|
if (mediaAll.length) {
|
|
|
|
colSel.$breakpoints
|
|
|
|
.prop('disabled', false)
|
2016-01-11 02:03:29 +00:00
|
|
|
.text( tsColSel.queryAll.replace(/\[columns\]/g, mediaAll.join(',')) + breakpts );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updateCols: function(c, wo) {
|
|
|
|
if (wo.columnSelector_mediaquery && c.selector.auto || c.selector.isInitializing) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-19 16:49:21 +00:00
|
|
|
var column,
|
2015-07-23 04:29:51 +00:00
|
|
|
colSel = c.selector,
|
|
|
|
styles = [],
|
|
|
|
prefix = c.namespace + 'columnselector';
|
|
|
|
colSel.$container.find('input[data-column]').filter('[data-column!="auto"]').each(function(){
|
|
|
|
if (!this.checked) {
|
|
|
|
column = parseInt( $(this).attr('data-column'), 10 ) + 1;
|
2015-10-19 16:49:21 +00:00
|
|
|
styles = styles.concat( tsColSel.addSelectors( prefix, column ) );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
$(this).toggleClass( wo.columnSelector_cssChecked, this.checked );
|
2013-12-17 23:39:39 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
if (wo.columnSelector_mediaquery){
|
|
|
|
colSel.$breakpoints.prop('disabled', true);
|
2013-12-17 23:39:39 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
if (colSel.$style) {
|
2016-01-11 02:03:29 +00:00
|
|
|
colSel.$style.prop('disabled', false).text( styles.length ? styles.join(',') + ' { display: none; }' : '' );
|
2013-12-17 23:39:39 +00:00
|
|
|
}
|
2016-04-30 00:47:41 +00:00
|
|
|
tsColSel.saveValues( c, wo );
|
2015-10-27 16:45:43 +00:00
|
|
|
tsColSel.adjustColspans( c, wo );
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler(wo.columnSelector_updated);
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-10-27 16:45:43 +00:00
|
|
|
setUpColspan: function(c, wo) {
|
|
|
|
var index, span, nspace,
|
2015-10-30 20:28:32 +00:00
|
|
|
$window = $( window ),
|
2015-10-27 16:45:43 +00:00
|
|
|
hasSpans = false,
|
|
|
|
$cells = c.$table
|
|
|
|
.add( $(c.namespace + '_extra_table') )
|
2016-01-10 19:58:13 +00:00
|
|
|
.children()
|
2015-10-27 16:45:43 +00:00
|
|
|
.children('tr')
|
|
|
|
.children('th, td'),
|
|
|
|
len = $cells.length;
|
|
|
|
for ( index = 0; index < len; index++ ) {
|
|
|
|
span = $cells[ index ].colSpan;
|
|
|
|
if ( span > 1 ) {
|
|
|
|
hasSpans = true;
|
|
|
|
$cells.eq( index )
|
|
|
|
.addClass( c.namespace.slice( 1 ) + 'columnselectorHasSpan' )
|
|
|
|
.attr( 'data-col-span', span );
|
2016-01-10 19:58:13 +00:00
|
|
|
// add data-column values
|
2016-01-11 02:03:29 +00:00
|
|
|
ts.computeColumnIndex( $cells.eq( index ).parent().addClass( 'hasSpan' ) );
|
2015-10-27 16:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// only add resize end if using media queries
|
|
|
|
if ( hasSpans && wo.columnSelector_mediaquery ) {
|
2016-06-30 01:19:20 +00:00
|
|
|
nspace = c.namespace + 'columnselector';
|
2015-10-27 16:45:43 +00:00
|
|
|
// Setup window.resizeEnd event
|
2015-10-30 20:28:32 +00:00
|
|
|
$window
|
2015-10-27 16:45:43 +00:00
|
|
|
.off( nspace )
|
|
|
|
.on( 'resize' + nspace, ts.window_resize )
|
|
|
|
.on( 'resizeEnd' + nspace, function() {
|
|
|
|
// IE calls resize when you modify content, so we have to unbind the resize event
|
|
|
|
// so we don't end up with an infinite loop. we can rebind after we're done.
|
2015-10-30 20:28:32 +00:00
|
|
|
$window.off( 'resize' + nspace, ts.window_resize );
|
2015-10-27 16:45:43 +00:00
|
|
|
tsColSel.adjustColspans( c, wo );
|
2015-10-30 20:28:32 +00:00
|
|
|
$window.on( 'resize' + nspace, ts.window_resize );
|
2015-10-27 16:45:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
adjustColspans: function(c, wo) {
|
2016-01-11 02:03:29 +00:00
|
|
|
var index, cols, col, span, end, $cell,
|
2015-10-27 16:45:43 +00:00
|
|
|
colSel = c.selector,
|
2016-06-30 01:19:20 +00:00
|
|
|
filtered = wo.filter_filteredRow || 'filtered',
|
|
|
|
autoModeOn = wo.columnSelector_mediaquery && colSel.auto,
|
|
|
|
// find all header/footer cells in case a regular column follows a colspan; see #1238
|
|
|
|
$headers = c.$table.children( 'thead, tfoot' ).children().children()
|
|
|
|
.add( $(c.namespace + '_extra_table').children( 'thead, tfoot' ).children().children() ),
|
|
|
|
len = $headers.length;
|
|
|
|
for ( index = 0; index < len; index++ ) {
|
|
|
|
$cell = $headers.eq(index);
|
|
|
|
col = parseInt( $cell.attr('data-column'), 10 ) || $cell[0].cellIndex;
|
|
|
|
span = parseInt( $cell.attr('data-col-span'), 10 ) || 1;
|
|
|
|
end = col + span;
|
|
|
|
if ( span > 1 ) {
|
2015-10-27 16:45:43 +00:00
|
|
|
for ( cols = col; cols < end; cols++ ) {
|
|
|
|
if ( !autoModeOn && colSel.states[ cols ] === false ||
|
|
|
|
autoModeOn && c.$headerIndexed[ cols ] && !c.$headerIndexed[ cols ].is(':visible') ) {
|
|
|
|
span--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( span ) {
|
2016-06-30 01:19:20 +00:00
|
|
|
$cell.removeClass( filtered )[0].colSpan = span;
|
2015-10-27 16:45:43 +00:00
|
|
|
} else {
|
2016-06-30 01:19:20 +00:00
|
|
|
$cell.addClass( filtered );
|
2015-10-27 16:45:43 +00:00
|
|
|
}
|
2016-07-28 20:36:55 +00:00
|
|
|
} else if ( typeof colSel.states[ col ] !== 'undefined' && colSel.states[ col ] !== null ) {
|
2016-06-30 01:19:20 +00:00
|
|
|
$cell.toggleClass( filtered, !colSel.states[ col ] );
|
2015-10-27 16:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-30 00:47:41 +00:00
|
|
|
saveValues : function( c, wo ) {
|
|
|
|
if ( wo.columnSelector_saveColumns && ts.storage ) {
|
|
|
|
var colSel = c.selector;
|
|
|
|
ts.storage( c.$table[0], 'tablesorter-columnSelector-auto', { auto : colSel.auto } );
|
|
|
|
ts.storage( c.$table[0], 'tablesorter-columnSelector', colSel.states );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
attachTo : function(table, elm) {
|
|
|
|
table = $(table)[0];
|
|
|
|
var colSel, wo, indx,
|
|
|
|
c = table.config,
|
|
|
|
$popup = $(elm);
|
|
|
|
if ($popup.length && c) {
|
|
|
|
if (!$popup.find('.tablesorter-column-selector').length) {
|
|
|
|
// add a wrapper to add the selector into, in case the popup has other content
|
|
|
|
$popup.append('<span class="tablesorter-column-selector"></span>');
|
|
|
|
}
|
|
|
|
colSel = c.selector;
|
|
|
|
wo = c.widgetOptions;
|
|
|
|
$popup.find('.tablesorter-column-selector')
|
|
|
|
.html( colSel.$container.html() )
|
|
|
|
.find('input').each(function(){
|
|
|
|
var indx = $(this).attr('data-column'),
|
|
|
|
isChecked = indx === 'auto' ? colSel.auto : colSel.states[indx];
|
|
|
|
$(this)
|
|
|
|
.toggleClass( wo.columnSelector_cssChecked, isChecked )
|
|
|
|
.prop( 'checked', isChecked );
|
|
|
|
});
|
2016-07-21 02:06:52 +00:00
|
|
|
colSel.$popup = $popup.on('change', 'input', function() {
|
|
|
|
if (!colSel.isInitializing) {
|
|
|
|
if (tsColSel.checkChange(c, this.checked)) {
|
|
|
|
// data input
|
|
|
|
indx = $(this).toggleClass( wo.columnSelector_cssChecked, this.checked ).attr('data-column');
|
|
|
|
// update original popup
|
|
|
|
colSel.$container.find('input[data-column="' + indx + '"]')
|
|
|
|
.prop('checked', this.checked)
|
|
|
|
.trigger('change');
|
|
|
|
} else {
|
|
|
|
this.checked = !this.checked;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-02-06 04:20:25 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2014-02-06 04:20:25 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-10-27 16:45:43 +00:00
|
|
|
/* Add window resizeEnd event (also used by scroller widget) */
|
|
|
|
ts.window_resize = function() {
|
|
|
|
if ( ts.timer_resize ) {
|
|
|
|
clearTimeout( ts.timer_resize );
|
|
|
|
}
|
|
|
|
ts.timer_resize = setTimeout( function() {
|
|
|
|
$( window ).trigger( 'resizeEnd' );
|
|
|
|
}, 250 );
|
|
|
|
};
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
ts.addWidget({
|
|
|
|
id: 'columnSelector',
|
|
|
|
priority: 10,
|
|
|
|
options: {
|
|
|
|
// target the column selector markup
|
|
|
|
columnSelector_container : null,
|
|
|
|
// column status, true = display, false = hide
|
|
|
|
// disable = do not display on list
|
|
|
|
columnSelector_columns : {},
|
|
|
|
// remember selected columns
|
|
|
|
columnSelector_saveColumns: true,
|
|
|
|
|
|
|
|
// container layout
|
|
|
|
columnSelector_layout : '<label><input type="checkbox">{name}</label>',
|
2016-12-14 21:43:30 +00:00
|
|
|
// layout customizer callback called for each column
|
|
|
|
// function($cell, name, column){ return name || $cell.html(); }
|
|
|
|
columnSelector_layoutCustomizer : null,
|
2015-07-23 04:29:51 +00:00
|
|
|
// data attribute containing column name to use in the selector container
|
2016-07-21 02:06:52 +00:00
|
|
|
columnSelector_name : 'data-selector-name',
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
/* Responsive Media Query settings */
|
|
|
|
// enable/disable mediaquery breakpoints
|
2016-07-21 02:06:52 +00:00
|
|
|
columnSelector_mediaquery : true,
|
2015-07-23 04:29:51 +00:00
|
|
|
// toggle checkbox name
|
2016-07-21 02:06:52 +00:00
|
|
|
columnSelector_mediaqueryName : 'Auto: ',
|
2015-07-23 04:29:51 +00:00
|
|
|
// breakpoints checkbox initial setting
|
2016-07-21 02:06:52 +00:00
|
|
|
columnSelector_mediaqueryState : true,
|
2015-10-19 16:49:21 +00:00
|
|
|
// hide columnSelector false columns while in auto mode
|
2016-07-21 02:06:52 +00:00
|
|
|
columnSelector_mediaqueryHidden : false,
|
|
|
|
// set the maximum and/or minimum number of visible columns
|
|
|
|
columnSelector_maxVisible : null,
|
|
|
|
columnSelector_minVisible : null,
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// responsive table hides columns with priority 1-6 at these breakpoints
|
|
|
|
// see http://view.jquerymobile.com/1.3.2/dist/demos/widgets/table-column-toggle/#Applyingapresetbreakpoint
|
|
|
|
// *** set to false to disable ***
|
|
|
|
columnSelector_breakpoints : [ '20em', '30em', '40em', '50em', '60em', '70em' ],
|
2016-04-30 02:08:29 +00:00
|
|
|
// maximum number of priority settings; if this value is changed (especially increased),
|
|
|
|
// then make sure to modify the columnSelector_breakpoints - see #1204
|
|
|
|
columnSelector_maxPriorities : 6,
|
2015-07-23 04:29:51 +00:00
|
|
|
// data attribute containing column priority
|
|
|
|
// duplicates how jQuery mobile uses priorities:
|
|
|
|
// http://view.jquerymobile.com/1.3.2/dist/demos/widgets/table-column-toggle/
|
|
|
|
columnSelector_priority : 'data-priority',
|
|
|
|
// class name added to checked checkboxes - this fixes an issue with Chrome not updating FontAwesome
|
|
|
|
// applied icons; use this class name (input.checked) instead of input:checked
|
2015-08-21 21:58:21 +00:00
|
|
|
columnSelector_cssChecked : 'checked',
|
|
|
|
// event triggered when columnSelector completes
|
|
|
|
columnSelector_updated : 'columnUpdate'
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
init: function(table, thisWidget, c, wo) {
|
|
|
|
tsColSel.init(table, c, wo);
|
|
|
|
},
|
|
|
|
remove: function(table, c, wo, refreshing) {
|
|
|
|
var csel = c.selector;
|
2016-01-28 10:27:47 +00:00
|
|
|
if ( refreshing || !csel ) { return; }
|
2017-05-25 10:10:33 +00:00
|
|
|
if ( csel ) { csel.$container.empty(); }
|
|
|
|
if ( csel.$popup ) { csel.$popup.empty(); }
|
2015-07-23 04:29:51 +00:00
|
|
|
csel.$style.remove();
|
|
|
|
csel.$breakpoints.remove();
|
2016-04-30 01:40:19 +00:00
|
|
|
$( c.namespace + 'columnselectorHasSpan' ).removeClass( wo.filter_filteredRow || 'filtered' );
|
2017-07-04 16:59:53 +00:00
|
|
|
c.$table.children('thead, tfoot').find('[data-col-span]').each(function(indx, el) {
|
|
|
|
var $el = $(el);
|
|
|
|
console.log($el, $el.attr('data-col-span'));
|
|
|
|
$el.attr('colspan', $el.attr('data-col-span'));
|
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
c.$table.off('updateAll' + namespace + ' update' + namespace);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2013-12-17 23:39:39 +00:00
|
|
|
|
|
|
|
})(jQuery);
|