- Is it possible to disable some columns for the export ? (i don't want them in the csv or xls since they'll be empty)
- When the column contain an image, instead of exporting an empty column, could you export the image alt attribute ?
Got it by altering this line :
if ( _DTSettings.aoColumns[i].bVisible )
To :
if ( _DTSettings.aoColumns[i].bVisible && _DTSettings.aoColumns[i].bSearchable )
And adding bSearchable to true to almost all my columns :)
It's not the perfect solution (I tried to create a bExportable parameter but failed) but it works.
Further to your comment on 26th September: "@JustLikeIcarus: Line 522 "if ( _DTSettings.aoColumns[i].bVisible )" is the key here. Just remove that and it will include your hidden data."
I'd just like to add that I also had a need for this, in order to make a large table with around 40 columns export as a CSV, but allow me to pick just a handful of them to display on the page using the { "bVisible": false } command.
If you added native functionality for this in a future release, I think that'd be great. If you did, please be sure to mention it in the release notes so that I can un-hack my hacks! :-)
If you have a look at the TableTools version which is included in the 1.5.4 DataTables download (in the 'extras' directory) you'll be able to see that this is actually a development version of TableTools, which includes a number of fixes and improvements. One of these improvements is to have a settings variable called 'bIncHiddenColumns' - setting this to true will include hidden columns in the data output, false will of course do the opposite.
Does this do the trick for you?
It's not a full release of TableTools yet because I think there is a UTF8 issue somewhere, but as of yet, I've been completely unable to confirm this...
Thanks for the pointer Allan - I didn't even notice that at the time and only found TableTools separately via this forum when I came on here to search for a few things. I'll check this version out and give it a try.
Y'all have done a great work with datatables/tabletools/forum.
I am experiencing a problem and I would appreciate if you can help me out with my problem, too.
I have the following configuration working:
- datatables 1.5.2 + datatools 1.0.2 + server side processing + pagination (10 lines / page).
Whenever I try to save to csv/xls/clipboard, it will save only the current visible page (10 lines), however I need all pages to be saved to file. Is this functionality missing for server side processing or I am doing something wrong?
This is the configuration I use (the php file is derived from the one presented in help documentation):
The reason that this is occurring is that TableTools is designed to work on the client-side only - it doesn't really take the server-side processing option of DataTables into account. There are two reasons for this, firstly keeping it client-side only makes it very easy to install on any platform, and secondly if you are using a database will millions of records, you probably don't want someone to just export the whole thing to excel with a single click.
If you are using a reasonably small database, then you can do what you are looking for by setting the display length (_iDisplayLength) of the table to be -1 (show all records) when the table is to be exported/copied and then setting it back once the copy is complete. This will require a little hacking in the TableTools script.
If you are using a larger database, then you need to consider using a server-side process to save the file to xsl or whatever, as there is a limit to the amount of data that Flash and Javascript can transfer between them (although this is something I'm looking at getting around in future versions). It would also be faster on the server-side when you are already using server-side processing.
Great product. The ease of use and implementation is great.
One issue, that I think has come up in this discussion, was the accents of letters when exporting to Excel. I'm using French. And this resolves to some weird characters.
I am also looking to implement exactly this feature of hiding one column while printing. I have tried quite a few things but so far no success. I was able to get the column disappear while printing by using the following code in fnFeaturePrint() method
[code]
_DTSettings.aoColumns[_DTSettings.aoColumns.length-1].bVisible = false;
_DTSettings.oApi._fnDrawHead(_DTSettings);
_DTSettings.oApi._fnGatherData(_DTSettings);
[/code]
While this is printing fine, I am not able to get the column back after pressing escape. The following code in fnPrintEnd() method will not work.
[code]
I went thru the code and understand why it will not work - but I do not seem to have a way out.
Is there any easier way for making this work. The best solution seems to be using fnSetColumnVis() method, but I am not able to call this method from within the ToolTables.js.
This code should be in
[code]function fnPrintShowNodes()[/code]. Not in fnPrintEnd(). Please see my post above.
If this doesn't work, I have an other idea. Add a class called 'noprint' to a particular column, which you do want to print.
In print.css
[code][/code]
make that class
[code].noprint{
display: none;
}[/code]
@aysa, even when I put the code in fnPrintShowNodes(), the last column does not show up.
Can you post the peice of code on how exactly to add the noprint class to the column? I tried in multiple ways and am getting javascript errors.
I tried using Jonas solution to hide a column before exporting to excel but it does not appear to work. No errors were reported but the undesirable column still appeared in the export. Does anyone know how to hide a column before exporting using the Tabletools?
Modifying the tabletools core files may not be an option for me since I use tabletools functionality in many of my pages and would not want to affect them adversely.
Thanks for useful plugin. But I need localized text for buttons. And I do a small changes in plugin code:
in "var TableToolsInit" add after "_iNextId": 1
[code]
,
"lang": {
"ln_csv": "Save as CSV",
"ln_excel": "Save for Excel",
"ln_clipboard": "Copy to clipboard",
"ln_print": "Print table"
}
[/code]
find "fnGlue()" in function "fnFeatureSaveCSV" and replace
[code]fnGlue( clip, nButton, "ToolTables_CSV_"+_iId, "Save as CSV" );[/code]
to
[code]fnGlue( clip, nButton, "ToolTables_CSV_"+_iId, _oSettings.lang.ln_csv );[/code]
find "fnGlue()" in function "fnFeatureSaveXLS" and replace
[code]fnGlue( clip, nButton, "ToolTables_XLS_"+_iId, "Save for Excel" );[/code]
to
[code]fnGlue( clip, nButton, "ToolTables_XLS_"+_iId, _oSettings.lang.ln_excel );[/code]
find "fnGlue()" in function "fnFeatureClipboard" and replace
[code]fnGlue( clip, nButton, "ToolTables_Copy_"+_iId, "Copy to clipboard" );[/code]
to
[code]fnGlue( clip, nButton, "ToolTables_Copy_"+_iId, _oSettings.lang.ln_clipboard );[/code]
find "nButton.title" in function "fnFeaturePrint" and replace
to
[code]nButton.title = _oSettings.lang.ln_print;[/code]
And in code, before dataTable initialization (e.g. for testing):
[code]TableToolsInit.lang = {ln_clipboard: "Save to my cool clipboard", ln_csv: "Save as comas separated file", ln_excel: "Save as MS Ofice Excel", ln_print: "Get table for printing"};
[/code]
Now I've a small bug with this plugin. After preview print page and press Esc button I've see the progress indicator. Any ideas how to fix it?
Added
After some reading API documentation I've found fnProcessingIndicator function. But when I type
[code]_DTSettings.oApi._fnProcessingDisplay(_oSettings, false);[/code]
in fnPrintEnd function, problem still exists and error console report what no errors wa found.
i proud of you to make the great script.....
i have a problem, when i use table tools in datatables, print, csv, and excel cannot load n css is broken...
may alan help me. this my code[i use data dinamic from database]
second question :)
how if i want to insert header n footer to document print..
the value of datatables in head n foot, i want to insert default my logo company..
please help me...
anybody can help me, what's wrong about the code.
search table, search entry, and showing entry be double...
anybody can help me to fix that code to be right with each one entry?
thank you a lot of
Hi,
I have been working on DataTable and have used extensively in my projects. Now I wanted to export the table data in CSV. But the complication is I wanted to export only the seen data. Meaning if I hide one column and export data, that hidden column and its data must not appear in that CSV. Has anyone done such kind of things? Thanks in advance
Why does clicking on the Print icon fire background processing? This would not be a big deal except that it fires twice and the first call in the stack returns nothing which throws a javascript error.
Thanks Allan, Sorry for the confusion on my part. I mean that with PHP background processing enabled, whenever a user clicks on the Print icon, the table kicks off a data search. The search takes a long time to finish. It's weird that it kicks off two simultanious searches as well. One of them succeeds, and the other one fails because no data is returned. I would link you but it is an internally protected resource behind several firewalls. Perhaps I'll try to whip something up sometime in a demo to show you. For now, I have removed the print icon.
Replies
- Is it possible to disable some columns for the export ? (i don't want them in the csv or xls since they'll be empty)
- When the column contain an image, instead of exporting an empty column, could you export the image alt attribute ?
Thanks :)
sLoopData = mTypeData.replace(/\n/g," ").replace( /<.*?>/g, "" );
To :
sLoopData = mTypeData.replace(/\n/g," ").replace( //g, "$1" ).replace( /<.*?>/g, "" );
if ( _DTSettings.aoColumns[i].bVisible )
To :
if ( _DTSettings.aoColumns[i].bVisible && _DTSettings.aoColumns[i].bSearchable )
And adding bSearchable to true to almost all my columns :)
It's not the perfect solution (I tried to create a bExportable parameter but failed) but it works.
Further to your comment on 26th September: "@JustLikeIcarus: Line 522 "if ( _DTSettings.aoColumns[i].bVisible )" is the key here. Just remove that and it will include your hidden data."
I'd just like to add that I also had a need for this, in order to make a large table with around 40 columns export as a CSV, but allow me to pick just a handful of them to display on the page using the { "bVisible": false } command.
If you added native functionality for this in a future release, I think that'd be great. If you did, please be sure to mention it in the release notes so that I can un-hack my hacks! :-)
Thanks,
Stephen
If you have a look at the TableTools version which is included in the 1.5.4 DataTables download (in the 'extras' directory) you'll be able to see that this is actually a development version of TableTools, which includes a number of fixes and improvements. One of these improvements is to have a settings variable called 'bIncHiddenColumns' - setting this to true will include hidden columns in the data output, false will of course do the opposite.
Does this do the trick for you?
It's not a full release of TableTools yet because I think there is a UTF8 issue somewhere, but as of yet, I've been completely unable to confirm this...
Regards,
Allan
Thanks,
Stephen
Y'all have done a great work with datatables/tabletools/forum.
I am experiencing a problem and I would appreciate if you can help me out with my problem, too.
I have the following configuration working:
- datatables 1.5.2 + datatools 1.0.2 + server side processing + pagination (10 lines / page).
Whenever I try to save to csv/xls/clipboard, it will save only the current visible page (10 lines), however I need all pages to be saved to file. Is this functionality missing for server side processing or I am doing something wrong?
This is the configuration I use (the php file is derived from the one presented in help documentation):
[code]
oTable = $('#example').dataTable( {
//"bStateSave": true,
"sDom": 'T<"top"l>rt<"bottom"pi><"clear">',
"aaSorting": [[10,'desc']],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "getdb.php",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"oLanguage": {
"sLengthMenu": 'Display '+
'10'+
'20'+
'30'+
'40'+
'50'+
'75'+
'100'+
'All'+
' records'
},
"bAutoWidth": false,
"aoColumns" : [
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" },
{ "sWidth": "10px" }
]
} );
[/code]
Thank you,
Flavius.
The reason that this is occurring is that TableTools is designed to work on the client-side only - it doesn't really take the server-side processing option of DataTables into account. There are two reasons for this, firstly keeping it client-side only makes it very easy to install on any platform, and secondly if you are using a database will millions of records, you probably don't want someone to just export the whole thing to excel with a single click.
If you are using a reasonably small database, then you can do what you are looking for by setting the display length (_iDisplayLength) of the table to be -1 (show all records) when the table is to be exported/copied and then setting it back once the copy is complete. This will require a little hacking in the TableTools script.
If you are using a larger database, then you need to consider using a server-side process to save the file to xsl or whatever, as there is a limit to the amount of data that Flash and Javascript can transfer between them (although this is something I'm looking at getting around in future versions). It would also be faster on the server-side when you are already using server-side processing.
Hope this helps,
Allan
Thanks a million. It make sense. I will implement the server side export.
Flavius.
I've just updated to 1.6.0 of DataTables and 1.1.0 of TableTools and have found that the bIncHiddenColumns works just as described, so thanks. :-)
Stephen
Great product. The ease of use and implementation is great.
One issue, that I think has come up in this discussion, was the accents of letters when exporting to Excel. I'm using French. And this resolves to some weird characters.
Has this been resolved, or a fix for this issue?
Yup - TableTools 1.1.x (1.1.4 is the current version at time of writing) should deal with UTF8 no problem now.
Allan
[code]
var oTable = $('#my_table').dataTable({...});
$("div.TableTools").mouseenter(function() {
oTable .fnSetColumnVis( 0, false );
});
$("div.TableTools").mouseleave(function() {
oTable .fnSetColumnVis( 0, true );
});
[/code]
When the mouse cursor enters the TableTool class, my first column is hidden. When I move the cursor out, it comes back.
Still need to find appropriate way of hiding a column when printing ;)
Thank you! I was coming in to ask just this...lol
I have
$(document).ready(function(){
$("div.TableTools").mouseenter(function() {
alert('removing view...');
});
});
In function fnGetDataTablesData() at line 655 i made i
[code]
_DTSettings.aoColumns[_DTSettings.aoColumns.length-1].bVisible = false;
_DTSettings.oApi._fnDrawHead(_DTSettings);
_DTSettings.oApi._fnGatherData(_DTSettings);
[/code]
While this is printing fine, I am not able to get the column back after pressing escape. The following code in fnPrintEnd() method will not work.
[code]
_DTSettings.aoColumns[_DTSettings.aoColumns.length-1].bVisible = true;
_DTSettings.oApi._fnDrawHead(_DTSettings);
_DTSettings.oApi._fnGatherData(_DTSettings);
[/code]
I went thru the code and understand why it will not work - but I do not seem to have a way out.
Is there any easier way for making this work. The best solution seems to be using fnSetColumnVis() method, but I am not able to call this method from within the ToolTables.js.
Any help would be appreciated.
Thanks,
Rajs
[code]
_DTSettings.aoColumns[_DTSettings.aoColumns.length-1].bVisible = true;
_DTSettings.oApi._fnDrawHead(_DTSettings);
_DTSettings.oApi._fnGatherData(_DTSettings);
[/code]
This code should be in
[code]function fnPrintShowNodes()[/code]. Not in fnPrintEnd(). Please see my post above.
If this doesn't work, I have an other idea. Add a class called 'noprint' to a particular column, which you do want to print.
In print.css
[code][/code]
make that class
[code].noprint{
display: none;
}[/code]
While printing the column will be invisible....
thank you
aysa
Can you post the peice of code on how exactly to add the noprint class to the column? I tried in multiple ways and am getting javascript errors.
Thanks in advance,
[code]
Request ID
Name
#id#
#firstname# #lastname#
EDIT
[/code]
In print.css
[code]
.noprint{
display: none;
}
[/code]
When you click on table tool print button, the column will appear but when you click on print from menu browser, it will not print.
If you still have the problem, you can drop me an email cf.saritha at gmail dot com
I tried using Jonas solution to hide a column before exporting to excel but it does not appear to work. No errors were reported but the undesirable column still appeared in the export. Does anyone know how to hide a column before exporting using the Tabletools?
Modifying the tabletools core files may not be an option for me since I use tabletools functionality in many of my pages and would not want to affect them adversely.
Thanks
in "var TableToolsInit" add after "_iNextId": 1
[code]
,
"lang": {
"ln_csv": "Save as CSV",
"ln_excel": "Save for Excel",
"ln_clipboard": "Copy to clipboard",
"ln_print": "Print table"
}
[/code]
find "fnGlue()" in function "fnFeatureSaveCSV" and replace
[code]fnGlue( clip, nButton, "ToolTables_CSV_"+_iId, "Save as CSV" );[/code]
to
[code]fnGlue( clip, nButton, "ToolTables_CSV_"+_iId, _oSettings.lang.ln_csv );[/code]
find "fnGlue()" in function "fnFeatureSaveXLS" and replace
[code]fnGlue( clip, nButton, "ToolTables_XLS_"+_iId, "Save for Excel" );[/code]
to
[code]fnGlue( clip, nButton, "ToolTables_XLS_"+_iId, _oSettings.lang.ln_excel );[/code]
find "fnGlue()" in function "fnFeatureClipboard" and replace
[code]fnGlue( clip, nButton, "ToolTables_Copy_"+_iId, "Copy to clipboard" );[/code]
to
[code]fnGlue( clip, nButton, "ToolTables_Copy_"+_iId, _oSettings.lang.ln_clipboard );[/code]
find "nButton.title" in function "fnFeaturePrint" and replace
to
[code]nButton.title = _oSettings.lang.ln_print;[/code]
And in code, before dataTable initialization (e.g. for testing):
[code]TableToolsInit.lang = {ln_clipboard: "Save to my cool clipboard", ln_csv: "Save as comas separated file", ln_excel: "Save as MS Ofice Excel", ln_print: "Get table for printing"};
[/code]
Added
After some reading API documentation I've found fnProcessingIndicator function. But when I type
[code]_DTSettings.oApi._fnProcessingDisplay(_oSettings, false);[/code]
in fnPrintEnd function, problem still exists and error console report what no errors wa found.
i proud of you to make the great script.....
i have a problem, when i use table tools in datatables, print, csv, and excel cannot load n css is broken...
may alan help me. this my code[i use data dinamic from database]
@import "media/css/demo_page.css";
@import "media/css/demo_table.css";
@import "media/css/TableTools.css";
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'json_source.php'
} );
} );
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip'
} );
} );
second question :)
how if i want to insert header n footer to document print..
the value of datatables in head n foot, i want to insert default my logo company..
please help me...
thank you Alan
TableToolsInit.sPrintMessage = "Print header message!";
var oTable = $('#example').dataTable( {
"sDom": 'T<"clear">lfrtip'
} );
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'json_source.php'
} );
} );
anybody can help me, what's wrong about the code.
search table, search entry, and showing entry be double...
anybody can help me to fix that code to be right with each one entry?
thank you a lot of
I have been working on DataTable and have used extensively in my projects. Now I wanted to export the table data in CSV. But the complication is I wanted to export only the seen data. Meaning if I hide one column and export data, that hidden column and its data must not appear in that CSV. Has anyone done such kind of things? Thanks in advance
Allan
Many thanks for your response.