Previous code may not work properly if set val() via code.
Please use this corrected code for pqSelect change event, corrections made for iterations over newVal and oldVal.
//convert it into pqSelect.
$sel.pqSelect({
checkbox: true,
multiplePlaceholder: 'Select visible columns',
maxDisplay: 100,
width: 'auto'
})
.on('change', (function(){
//save initial value.
var oldVal = $sel.val() || [];
return function( evt ){
var newVal = $(this).val() || [],
diff, state;
//previously checked but unchecked now.
$(oldVal).not(newVal).get().forEach(function(di){
var column = grid.getColumn({dataIndx: di }),
filter = column.filter;
column.hidden = true;
if( filter && filter.on && filter.value != undefined ){//TODO: add other condition values like [] for range.
alert(di);
}
})
//previously unchecked but checked now.
$(newVal).not(oldVal).get().forEach(function(di){
grid.getColumn({dataIndx: di }).hidden = false;
})
grid.refreshCM();
grid.refresh();
console.log("diff: ", diff, " state: ", state);
oldVal = newVal;
}
})());