ColumnSelector: refresh method properly saves changes. Fixes #1198

This commit is contained in:
Rob Garrison 2016-04-29 19:47:41 -05:00
parent cc9d9c9412
commit 60f1eda06d
No known key found for this signature in database
GPG Key ID: 0A42D160D71978E1

View File

@ -67,19 +67,20 @@
}, },
refreshColumns: function( c, optName, optState ) { refreshColumns: function( c, optName, optState ) {
var i, arry, var i, arry, $el, val,
colSel = c.selector,
isArry = $.isArray(optState || optName), isArry = $.isArray(optState || optName),
wo = c.widgetOptions; wo = c.widgetOptions;
// see #798 // see #798
if (typeof optName !== 'undefined' && c.selector.$container.length) { if (typeof optName !== 'undefined' && colSel.$container.length) {
// pass "selectors" to update the all of the container contents // pass "selectors" to update the all of the container contents
if ( optName === 'selectors' ) { if ( optName === 'selectors' ) {
c.selector.$container.empty(); colSel.$container.empty();
tsColSel.setupSelector(c, wo); tsColSel.setupSelector(c, wo);
tsColSel.setupBreakpoints(c, wo); tsColSel.setupBreakpoints(c, wo);
// if optState is undefined, maintain the current "auto" state // if optState is undefined, maintain the current "auto" state
if ( typeof optState === 'undefined' ) { if ( typeof optState === 'undefined' ) {
optState = c.selector.auto; optState = colSel.auto;
} }
} }
// pass an array of column zero-based indexes to turn off auto mode & toggle selected columns // pass an array of column zero-based indexes to turn off auto mode & toggle selected columns
@ -90,20 +91,24 @@
arry[i] = parseInt(v, 10); arry[i] = parseInt(v, 10);
}); });
for (i = 0; i < c.columns; i++) { for (i = 0; i < c.columns; i++) {
c.selector.$container val = $.inArray( i, arry ) >= 0;
.find('input[data-column=' + i + ']') $el = colSel.$container.find( 'input[data-column=' + i + ']' );
.prop('checked', $.inArray( i, arry ) >= 0 ); if ( $el.length ) {
$el.prop( 'checked', val );
colSel.states[i] = val;
}
} }
} }
// if passing an array, set auto to false to allow manual column selection & update columns // if passing an array, set auto to false to allow manual column selection & update columns
// refreshColumns( c, 'auto', true ) === refreshColumns( c, true ); // refreshColumns( c, 'auto', true ) === refreshColumns( c, true );
tsColSel val = optState === true || optName === true || optName === 'auto' && optState !== false;
.updateAuto( c, wo, c.selector.$container.find('input[data-column="auto"]') $el = colSel.$container.find( 'input[data-column="auto"]' ).prop( 'checked', val );
.prop('checked', optState === true || optName === true || optName === 'auto' && optState !== false) ); tsColSel.updateAuto( c, wo, $el );
} else { } else {
tsColSel.updateBreakpoints(c, wo); tsColSel.updateBreakpoints(c, wo);
tsColSel.updateCols(c, wo); tsColSel.updateCols(c, wo);
} }
tsColSel.saveValues( c, wo );
tsColSel.adjustColspans( c, wo ); tsColSel.adjustColspans( c, wo );
}, },
@ -224,9 +229,7 @@
$(this).prop( 'checked', indx === 'auto' ? colSel.auto : colSel.states[indx] ); $(this).prop( 'checked', indx === 'auto' ? colSel.auto : colSel.states[indx] );
}); });
} }
if (wo.columnSelector_saveColumns && ts.storage) { tsColSel.saveValues( c, wo );
ts.storage( c.$table[0], 'tablesorter-columnSelector-auto', { auto : colSel.auto } );
}
tsColSel.adjustColspans( c, wo ); tsColSel.adjustColspans( c, wo );
// trigger columnUpdate if auto is true (it gets skipped in updateCols() // trigger columnUpdate if auto is true (it gets skipped in updateCols()
if (colSel.auto) { if (colSel.auto) {
@ -317,9 +320,7 @@
if (colSel.$style) { if (colSel.$style) {
colSel.$style.prop('disabled', false).text( styles.length ? styles.join(',') + ' { display: none; }' : '' ); colSel.$style.prop('disabled', false).text( styles.length ? styles.join(',') + ' { display: none; }' : '' );
} }
if (wo.columnSelector_saveColumns && ts.storage) { tsColSel.saveValues( c, wo );
ts.storage( c.$table[0], 'tablesorter-columnSelector', colSel.states );
}
tsColSel.adjustColspans( c, wo ); tsColSel.adjustColspans( c, wo );
c.$table.triggerHandler(wo.columnSelector_updated); c.$table.triggerHandler(wo.columnSelector_updated);
}, },
@ -388,6 +389,14 @@
} }
}, },
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 );
}
},
attachTo : function(table, elm) { attachTo : function(table, elm) {
table = $(table)[0]; table = $(table)[0];
var colSel, wo, indx, var colSel, wo, indx,