Reputation: 573
I have implement the excel export in datatable. Have included the the tabletool reference and SWF put into my local workspace.
var oTable = $("#products").dataTable({
"aaData": newarray,
"bProcessing": true,
"bDeferRender": true,
"bFilter": false,
"bRetrieve": true,
"bPaginate": true,
"bJQueryUI": true,
"sPaginationType": "two_button",
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "../swf/copy_csv_xls.swf",
"aButtons": [ "xls" ]
},
"bSort": true,
Its just displaying the Export option in table header, but there is no action , nothing happening.Is there any step i need to do ? if i'm keeping blank without mention oTableTools, print option is working fine , so my environment is working good.
Please advise which step i have not done ?
Thanks
Upvotes: 3
Views: 21360
Reputation: 3900
I eventually discovered that the reason why Export to Excel also creates a .csv file (which can be read by Excel) is because it is meant to do so. This is not a bug, it simply hasn't been implemented yet - see the discussion here: http://datatables.net/forums/discussion/4043/export-to-excel-wrong-extention-.csv./p1
The other issue is that the sSwfPath is important to specify correctly. It seems to work best when the full server path is used instead of a relative url? An alternative to using a local file is to use http://datatables.net/release-datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf
. UPDATE: This link no longer exists and I have not been able to find a replacement link yet.
Remove Excel button:
'oTableTools' : {
'aButtons': ['copy', 'csv', 'pdf', 'print']
};
Button options:
http://datatables.net/extras/tabletools/button_options
Button Icons and jQuery UI: DataTables TableTools images not working with ThemeRoller
Possible ways to create icons/positions for buttons, maybe:
<img src='..>
inside the sButtonText property of a buttonhtml('<img ..>')
of a buttonUpvotes: 9
Reputation: 791
Required Files
1)datatable/media/css/demo_table_jui.css
2)datatable/media/themes/smoothness/jquery-ui-1.8.4.custom.css
3)datatable/media/css/TableTools_JUI.css
4)datatable/media/js/1.9/jquery.dataTables.js
5)datatable/media/js/ZeroClipboard.js
6)datatable/media/js/TableTools.js
First use the `jquery datable js 1.9` (please check the below link where you can download this js)
and second use the code like below to view datatable
$('#example').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"oTableTools": {
"aButtons": [
{
'sExtends':'csv',
"sFileName": "filetitle.csv",
'mColumns':[0,1]
},
{
'sExtends':'pdf',
"sFileName": "filetitle.pdf",
'mColumns':[0,1]
},
]
},
"sDom": '<"H"Tlfr>tip<"F">',
"aoColumns":
[
{ "bSearchable": false },
null, // as per requirement
{ "bSortable": false, "bSearchable": false },
]
});
please remember main code for export to excel is as below
which is added in the above code
"oTableTools": {
"aButtons": [
{
'sExtends':'csv',
"sFileName": "subscribers.csv",
'mColumns':[0,1]
},
{
'sExtends':'pdf',
"sFileName": "subscribers.pdf",
'mColumns':[0,1]
},
]
},
"sDom": '<"H"Tlfr>tip<"F">',
and then download the "media" folder from this link and paste into the folder where you datagrid show
[Please check here](http://codeace.in/download/)
please check screenshot [here][2] as per required file from `media/swf/copy_csv_xls_pdf.swf` is required to export functionality.
`[NOTE : please extract and paste the "media" folder in the accurate path on which page your datatable is display .]`
[1]: http://codeace.in/download/1.9.zip
[2]: http://codeace.in/download/_2014-04-11%2013-57-20.png
Upvotes: 1