2016-02-29 56 views
2

对于我而言,我似乎无法让tablesorter的下载CSV功能起作用。我想也许这是我的设置有问题,所以我创建了一个裸露的测试表,但仍遇到同样的问题。Tablesorter输出为CSV将不会触发

根据official documentation,我需要tablesorter 2.8或更高(我在2.25.3)和jQuery 1.7或更高(我在拉动jQuery 1.12.0)。我遵循Mottie从this question的简单设置,但我没有运气。

下面是我的测试代码。我不得不失去一些明显的东西,但是在盯着它几个小时之后,我没有看到它。

<head> 
    <title>Table to CSV</title> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.25.4/js/jquery.tablesorter.combined.min.js"></script> 
</head> 
<body> 
    <button class="download">Download CSV</button> 
    <table class="tablesorter"> 
     <thead> 
      <tr> 
       <th>First Name</th> 
       <th>Last Name</th> 
       <th>Number</th> 
       <th>Food</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td>Billy</td> 
       <td>Bob</td> 
       <td>4</td> 
       <td>Pizza</td> 
      </tr> 
      <tr> 
       <td>Jill</td> 
       <td>Jackson</td> 
       <td>23</td> 
       <td>Tacos</td> 
      </tr> 
      <tr> 
       <td>Robert</td> 
       <td>Roy</td> 
       <td>6</td> 
       <td>Hamburger</td> 
      </tr> 
     </tbody> 
    </table> 

    <script> 
     $(document).ready(function(){ 
      var $table = $("table"); 

      $table.tablesorter({ 
       widgets: ["output"] 
      }); 

      $('.download').click(function(){ 
       $table.trigger("outputTable"); 
       console.log("Download clicked."); 
      }); 
     }); 
    </script> 
</body> 

编辑:用cloudflare's将我自己的[local] tabelsorter脚本src换出来。

+0

我粘贴你的代码,并运行它,并在调试器(F12),当它到达行$ table.tablesorter {{它说_object不支持属性或方法'tablesorter'_ –

+0

您是否正在加载自己的tablesorter?我在本地加载我的(见src标签),所以如果你没有修改它来加载你自己的,它不会找到它 感谢您的快速回复! – Steve

+0

我看到现在和我只是试图找到一个CDN,当你运行它时,你在F12控制台中看到了什么? –

回答

2

我认为你只缺少widget-output.js文件:

https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.25.4/js/widgets/widget-output.min.js

应该使用的tablesorter <script>后加载。点击this demo的“外部资源”部分查看您需要的所有文件(不包括jQuery)。

+0

公顷 - 我添加了这个参考,它为我工作....所以我很想知道我是否可以从F12控制台的某个地方收集这些缺失的参考资料? –

+0

我知道它必须是我的一些愚蠢的东西。非常感谢你,莫蒂!当我观看演示时,我在想如何能够看到正在加载的脚本 - 从不会注意到左侧的导航选项卡。 谢谢你。 – Steve

+0

@ Nick.McDermaid当'debug'选项被设置时,我可以在控制台中添加一个警告。 – Mottie