我在datatable中实现了excel导出。已将tabletool引用和SWF放入我的本地工作区。
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,
它只是在表头中显示导出选项,但没有动作,没有任何事情发生。我有什么步骤需要做吗?如果我保持空白而不提及oTableTools,打印选项工作正常,所以我的环境运行良好。
请告知我没有做哪一步?
由于
答案 0 :(得分:9)
我最终发现导出到Excel还会创建.csv文件(可以通过Excel读取)的原因是因为它是这样做的。这不是一个错误,它还没有实现 - 请参阅此处的讨论:http://datatables.net/forums/discussion/4043/export-to-excel-wrong-extention-.csv./p1
另一个问题是sSwfPath对于正确指定很重要。当使用完整服务器路径而不是相对URL时,它似乎工作得最好?使用本地文件的替代方法是使用http://datatables.net/release-datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf
。更新:此链接不再存在,我还无法找到替换链接。
删除Excel按钮:
'oTableTools' : {
'aButtons': ['copy', 'csv', 'pdf', 'print']
};
按钮选项:
http://datatables.net/extras/tabletools/button_options
按钮图标和jQuery UI:DataTables TableTools images not working with ThemeRoller
为按钮创建图标/位置的可能方法,可能是:
<img src='..>
html('<img ..>')
答案 1 :(得分:1)
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