Jquery datatable-Excel导出不工作
我已经在datatable中实现了excel导出。已将tabletool参考和SWF包含在我的本地工作区中Jquery datatable-Excel导出不工作,jquery,datatables,Jquery,Datatables,我已经在datatable中实现了excel导出。已将tabletool参考和SWF包含在我的本地工作区中 var oTable = $("#products").dataTable({ "aaData": newarray, "bProcessing": true, "bDeferRender": true, "bFilter": false, "bRetrieve": true, "bPaginate": t
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,
var-oTable=$(“#产品”).dataTable({
“aaData”:新数组,
“bProcessing”:正确,
“bDeferRender”:没错,
“bFilter”:错误,
“bRetrieve”:没错,
“bPaginate”:对,
“bJQueryUI”:没错,
“sPaginationType”:“两个按钮”,
“sDom”:“t”,
“可旋转工具”:{
“sSwfPath”:“./swf/copy_csv_xls.swf”,
“阿布顿”:[“xls”]
},
“bSort”:正确,
它只是在表格标题中显示导出选项,但没有任何操作,没有任何事情发生。我需要执行什么步骤吗?如果我保持空白而没有提及oTableTools,则打印选项工作正常,因此我的环境工作良好
请告知我还没有完成哪一步
谢谢我最终发现,为什么导出到Excel也会创建一个.csv文件(Excel可以读取该文件)是因为它要这样做。这不是一个bug,只是还没有实现而已-请参阅此处的讨论: 另一个问题是,正确指定sSwfPath很重要。如果使用完整的服务器路径而不是相对url,它似乎工作得最好?使用本地文件的另一种方法是使用
http://datatables.net/release-datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf
。更新:此链接已不存在,我尚未找到替代链接
删除Excel按钮:
'oTableTools' : {
'aButtons': ['copy', 'csv', 'pdf', 'print']
};
按钮选项:
按钮图标和jQuery UI:
为按钮创建图标/位置的可能方法,可能包括:
html(“”)
所需文件
1) datatable/media/css/demo_table_jui.css
2) 数据表/媒体/主题/平滑度/jquery-ui-1.8.4.custom.css
3) datatable/media/css/TableTools\u JUI.css
4) datatable/media/js/1.9/jquery.dataTables.js
5) datatable/media/js/ZeroClipboard.js
6) datatable/media/js/TableTools.js
首先使用“jquery datable js 1.9”(请查看下面的链接,您可以在那里下载此js)
然后使用下面的代码查看datatable
$('#示例')。数据表({
“bJQueryUI”:没错,
“sPaginationType”:“完整编号”,
“可旋转工具”:{
“阿布顿”:[
{
“sExtends”:“csv”,
“sFileName”:“filetitle.csv”,
“McColumns”:[0,1]
},
{
“sExtends”:“pdf”,
“sFileName”:“filetitle.pdf”,
“McColumns”:[0,1]
},
]
},
“sDom”:“提示”,
“aoColumns”:
[
{“可搜索”:false},
null,//根据需要
{“bSortable”:false,“bsearcable”:false},
]
});
请记住导出到excel的主要代码如下
这是在上面的代码中添加的
“可旋转工具”:{
“阿布顿”:[
{
“sExtends”:“csv”,
“sFileName”:“subscribers.csv”,
“McColumns”:[0,1]
},
{
“sExtends”:“pdf”,
“sFileName”:“subscribers.pdf”,
“McColumns”:[0,1]
},
]
},
“sDom”:“提示”,
然后从该链接下载“媒体”文件夹并粘贴到datagrid显示的文件夹中
[请检查这里](http://codeace.in/download/)
请根据“media/swf/copy\u csv\u xls\u pdf”中的所需文件检查[此处][2]屏幕截图。导出功能需要swf。
`[注意:请将“媒体”文件夹提取并粘贴到数据表显示页面的正确路径中。]`
[1]: http://codeace.in/download/1.9.zip
[2]: http://codeace.in/download/_2014-04-11%2013-57-20.png
有人知道这个问题吗?我不知道你的代码发生了什么,但这可能会帮助你尝试另一种初始化设置方法:可能尝试使用根相对url,比如“/tools/swf/copy\u csv\u xls.swf”…?请告诉我如何使用root-relative?很好,谢谢你的帮助。我会接受你的答案…再给我一个帮助,如何替换excel图标而不是按钮,按钮显示在左侧,但它假设b右侧看起来会很好。@user2444474我不是100%确定你的意思,但我已经在我的答案中添加了一些信息,其中ght帮助您。指向swf文件的链接已断开。重新加载的文件1)datatable/media/css/demo_table\u jui.css 2)datatable/media/themes/smooth/jquery-ui-1.8.4.custom.css 3)datatable/media/css/TableTools\u jui.css 4)datatable/media/js/1.9/jquery.dataTables.js.js 5)datatable/media/js/js/zerocip剪贴板.js 6)datatable/js/js
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