Mahdi.Pishguy Mahdi.Pishguy - 3 months ago 35
jQuery Question

export data to excel not working in datatables

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

Answer

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 .]

Comments