fnShowHide to filter exported csv
fnShowHide to filter exported csv
Hi Is it possible to get the fnShowHide to filter the exported csv and pdf / print etc ?, I have implemeted the fnShowHide like the tutorial but when I print using tabletools or export to csv all of the data is exported, also is it possible to change sRowSelect to select columns instead, so that on export only the selected columns are exported to csv ?.
Many Thanks :-)
Many Thanks :-)
This discussion has been closed.
Replies
The clue is in the parameter name :-). At some point I hope to get the chance to add column selection support to TableTools - but that is not currently implemented I'm sorry to say.
> I can hide columns ok using this, but need to pass the hidden columns onto tabletools csv export button
What I think you want is mColumns: http://datatables.net/extras/tabletools/button_options#mColumns . This will allow you to use visible columns only, hidden columns only, all columns, or you can specify your own array of column indexes. In theory that could actually be expanded to be a dynamic array that will allow the user to select which columns are to be exported - not something I've tried, but it should be perfectly possible by modifying that array :-)
Allan
I am trying to use mColumns with an array variable to select which columns are output. I'm doing this because I need the CSV to output the visible columns only, and exclude hidden columns. But there are a couple of columns that should always be excluded, even if their columns are visible. So in the DataTable's fnDrawCallback function I am building the array (initially declared at top-level so it is available within the scope of the oTableTools options...
So I am building my array of columns to include with the following code inside fnDrawCallback:
vCols = new Array();
$.each(oTable.fnSettings().aoColumns, function(c){
if(oTable.fnSettings().aoColumns[c].bVisible == true && c != 0 && c != 3){
vCols = vCols.concat(c);
}
});
So vCols basically includes all columns that are visible except it never includes column indexes 0 or 3.
The array is built correctly, as I have verified by outputting the results separately. But when I use it as the value of my mColumns option in the oTableTools declarations, it does not work, and it simply includes all columns in the output.
I have tested using an array variable in its simplest form just by declaring var testCols = [ 5, 6 ]; at the top-level in my javascript, then using that variable for mColumns, and it worked perfectly.
But then if instead I just declare var testCols; (no initial values) at top-level, and assign testCols = [ 5, 6 ]; inside the fnDrawCallback function, it no longer works, despite that the DrawCallback function is called, and it is placing a value into the array variable.
Can you help me out figuring this problem out?
Thanks in advance for any help.
My table implementation is found at http://collection.callahan09.com/comics
Because the fnDrawCallback function wasn't firing until after the oTableTools initialization, so the variable was empty when I was initializing TableTools. The next thing I tried was to write a seperate function called visibleColumns() and call it for mColumns, but it gave an error because the DataTables was not finished initializing at that point. So my solution, and it's working beautifully now, was the simply initialize TableTools after DataTables is finished initializing, using the alternate initialization method for TableTools.
http://datatables.net/release-datatables/extras/TableTools/alt_init.html
Hopefully this helps anyone facing a similar issue!
I have tried everything I can think of to solve this issue, but it just does not work.
My best guess, but still not working, was to do the following:
In the oColVis settings of my DataTable, I've utilized the fnStateChange function, within which I've got the following code:
oTableTools.s.buttonSet[0].mColumns = visibleColumns();
If I run through this javascript in debug mode, it seems to set the property just fine; it appears as though the correct work is occurring: whenever a column is made visible or hidden, the mColumns property for my "Copy" button is updated to reflect the new array of columns it should copy. But when I go to actually perform the Copy by pressing the button, it is as if it's still using the original mColumns value, not the one I've just set it to.
Is there any solution to this?
The only thing I can think of is to completely override the fnClick() function of the button and manually build the output with fnSetText(), which I suppose I'll try soon, but it seems odd to have to go to those lengths for this.
Simply utilize the following in the button definition:
"fnClick": function ( nButton, oConfig, oFlash ) {
oConfig.mColumns = visibleColumns();
this.fnSetText( oFlash, this.fnGetTableData(oConfig) );
},
Hope this helps someone if you stumble here looking for the same info.