对于我而言,我似乎无法让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换出来。
我粘贴你的代码,并运行它,并在调试器(F12),当它到达行$ table.tablesorter {{它说_object不支持属性或方法'tablesorter'_ –
您是否正在加载自己的tablesorter?我在本地加载我的(见src标签),所以如果你没有修改它来加载你自己的,它不会找到它 感谢您的快速回复! – Steve
我看到现在和我只是试图找到一个CDN,当你运行它时,你在F12控制台中看到了什么? –