colVis - get list of hidden or shown columns?
colVis - get list of hidden or shown columns?
bill.martino
Posts: 38Questions: 0Answers: 0
Is there a method to return a list of which columns are hidden or shown via the colVis plug-in?
I need to save the user's settings to a database so need to have a list of column names.
I need to save the user's settings to a database so need to have a list of column names.
This discussion has been closed.
Replies
Allan
also, for archival sakes, i had to use something along the lines of
oTable.fnSettings().aoColumns[ i ].bVisible
'aoColumns' instead of 'aoColumn'
Allan
"fnInfoCallback": function() {
vCols = new Array();
$.each(oTable.fnSettings().aoColumns, function(c){
if(oTable.fnSettings().aoColumns[c].bVisible == true){
vCols = vCols.concat(oTable.fnSettings().aoColumns[c].sName)
}
});
}
However I am unsure how to push this list to the ajax call. I tried
"fnServerData": function ( aoData){
aoData.push(vCols);
}
but it did not work, can you provide further guidance as to how to get this data to be included in the other variables sent to the ajax call?
I am using server-side processing and my ajax source is defined
I am receiving "vCols is not defined" because obviously the function does not know what my list variable is -
thanks!
Allan
Sorry to be a pest, but I have been plugging at this all last night to no avail.
thanks!
Allan
After much trial and error, this is what worked for me:
// get visible columns
$.fn.getColumnsShown = function(dTable)
{
vCols = new Array();
$.each(dTable.fnSettings().aoColumns, function(c){
if(dTable.fnSettings().aoColumns[c].bVisible == true){
vCols = vCols.concat(dTable.fnSettings().aoColumns[c].sName)
}
});
return vCols;
}
$(document).ready(function(){
// data table
var oTable = $('#resultTable').dataTable({
"fnServerData": function ( sSource, aoData, fnCallback ) {
columnsShown = $('#resultTable').getColumnsShown(this);
/* Add some extra data to the sender */
aoData.push( { "name": "visColumns", "value": columnsShown } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
} );
}
etc...
etc...
});
});
thanks again! Hope this may help someone in the future