3

I have implement the excel export in datatable. Have included the the tabletool reference and SWF put into my local workspace.

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,

Its just displaying the Export option in table header, but there is no action , nothing happening.Is there any step i need to do ? if i'm keeping blank without mention oTableTools, print option is working fine , so my environment is working good.

Please advise which step i have not done ?

Thanks

4

2 回答 2

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_x‌​ls_pdf.swf. 更新:此链接不再存在,我还没有找到替换链接。

删除 Excel 按钮:

'oTableTools' : {
    'aButtons': ['copy', 'csv', 'pdf', 'print']
};

按钮选项:

http://datatables.net/extras/tabletools/button_options

按钮图标和 jQuery UI:DataTables TableTools 图像不适用于 ThemeRoller

为按钮创建图标/位置的可能方法,可能是:

  1. 为按钮指定 CSS 背景图像和位置
  2. <img src='..>在按钮的 sButtonText 属性内使用
  3. 使用 jQuery 更改html('<img ..>')按钮的
于 2013-07-16T12:50:39.400 回答
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
于 2014-04-11T08:33:25.667 回答