export data to excel not working in datatables

浪尽此生 提交于 2019-12-04 14:23:30

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:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!