jquery - Tablesorter 输出到 CSV 不会触发

标签 jquery tablesorter

我,在我的一生中,似乎无法让 tablesorter 的下载到 CSV 功能发挥作用。我认为我的设置可能有问题,因此我创建了一个简单的测试表,但仍然遇到了同样的问题。

根据official documentation ,我需要 tablesorter 2.8 或更高版本(我使用的是 2.25.3)和 jQuery 1.7 或更高版本(我正在引入 jQuery 1.12.0)。我按照莫蒂自己的简单设置从 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 替换了我自己的 [本地] tabelsorter 脚本 src。

最佳答案

我想你只是错过了 widget-output.js文件:

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

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

关于jquery - Tablesorter 输出到 CSV 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35711501/

相关文章:

jquery - 带有页眉和页脚以及动态内容高度的 Css div

ruby-on-rails - 为什么 Rails 3 中的 AJAX 如此困难?或者说,我做错了什么?

javascript - 表排序器未生效

php - 使用tablesorter对jquery、php、mysql表进行排序

jquery - 如何在 JQuery 中加载 AJAX 内容后触发事件处理程序

jquery、tablesorter 过滤器和菜单 : menu goes away when overlap

jquery - 如何将样式表仅应用于我的 jquery datepicker 小部件?

javascript - TypeError .val() 不是我在 Javascript 上选择的答案中的函数

javascript - 使用拼接从数组中删除元素后。它没有重置。我的代码有什么错误吗

javascript - 使用过滤器小部件时是否可以按类定位特定的表排序器列?