Tablesorter 输出到 CSV 不会触发

Tablesorter output to CSV won't trigger

我这辈子似乎无法使用 tablesorter 的下载到 CSV 功能。我想可能是我的设置有问题,所以我创建了一个简单的测试 table 但仍然 运行 遇到同样的问题。

根据 official documentation, I need tablesorter 2.8 or higher (I'm on 2.25.3) and jQuery 1.7 or higher (I'm pulling in jQuery 1.12.0). I followed Mottie's own simple setup from 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> after tablesorter 加载。单击 this demo 的 "External Resources" 部分以查看您需要的所有文件(不包括 jQuery)。