export data and TableTools not working for me, after adding this line between head:
<script type="text/javascript" language="javascript" src="../../components/dataTables/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="../../components/dataTables/media/js/ZeroClipboard.js"></script>
<script type="text/javascript" language="javascript" src="../../components/dataTables/media/js/TableTools.js"></script>
and change table id prop in this:
$('#myTable').dataTable({
"sDom": '<"clear">lfrtipT'
});
i can see tableTools buttons on the table but, thay are not working
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": "subscribers_"+GetTodayDate()+".csv",
'mColumns':[0,1]
},
{
'sExtends':'pdf',
"sFileName": "subscribers_"+GetTodayDate()+".pdf",
'mColumns':[0,1]
},
]
},
"sDom": '<"H"Tlfr>tip<"F">',
"aoColumns":
[
{ "bSearchable": false },
null,
{ "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
[NOTE : please extract and paste the "media" folder in the accurate path on which page your datatable is display .]
For that you will need a file:
- copy_csv_xls_pdf.swf
You will get it here: Google Datatable SWF
Try following code:
$(document).ready( function () {
$('#myTable').dataTable( {
"sDom": '<"clear">lfrtipT',
"oTableTools": {
"sSwfPath" : "swf/copy_csv_xls_pdf.swf"
}
});
});
Where set sSwfPath
value to absolute path to the copy_csv_xls_pdf.swf
file.
Check this link for more info: TableTools example - setting SWF path
来源:https://stackoverflow.com/questions/13970883/export-data-to-excel-not-working-in-datatables