jQuery jquery数据表导出到excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25855993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:11:01  来源:igfitidea点击:

jquery datatables export to excel

jquerydatatable

提问by Mor

i'm trying to use TableTools to export the datatable (example) into excel or csv , I prefer Excel. but with this code below it's not even show me the icons (export/print/csv/..) I made several changes but nothing helped . . what am I doing wrong? what am I missing? there is any example of how to implement it? I also did it exactly as they do in the official site and it's still not working.

我正在尝试使用 TableTools 将数据表(示例)导出到 excel 或 csv 中,我更喜欢 Excel。但是使用下面的代码,它甚至没有向我显示图标(导出/打印/csv/..)我做了一些更改但没有任何帮助。. 我究竟做错了什么?我错过了什么?有没有如何实施它的例子?我也完全按照他们在官方网站上的做法进行了操作,但仍然无法正常工作。

<link rel="stylesheet" type="text/css" href="assets/jquery.dataTables.css">

<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.0/css/jquery.dataTables.css">
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>

 $.ajax({
   type: "POST",
   url: "server_processing_harigot.php",
   data: {
     str: str,
     hotel_id: hotel_id
   },
   cache: false,
   success: function(result) {
     data = JSON.parse(result);
     $.each(data, function(index, data) {
       //!!!--Here is the main catch------>fnAddData
       $('#example').dataTable().fnAddData([
         data.phone_number,
         data.name,
         data.client_id,
         data.employee

       ]);

     });

   }

 });
 $('#example').dataTable({
   "sDom": 'T<"clear">lfrtip',
   "oTableTools": {
     "sSwfPath": "swf/copy_csv_xls_pdf.swf"
   }
 });
<table width="100%" id="example" class="display" cellspacing="0">
  <caption><strong> example </strong>
  </caption>
  <thead>
    <tr>
      <th>phone_number</th>
      <th>name</th>
      <th>client_id</th>
      <th>employee</th>


    </tr>
  </thead>
  <tbody id="tablebody">
  </tbody>
</table>

any idea?

任何的想法?

回答by Aaron

You're missing the reference for dataTables.tableTools.jsand dataTables.tableTools.css.

您缺少的参考dataTables.tableTools.jsdataTables.tableTools.css

See herefor examples

有关示例,请参见此处

EDIT: This feature has now moved over to combination of using Buttons and Select extensions. See here.

编辑:此功能现在已转移到使用 Buttons 和 Select extensions 的组合。见这里