Tablesorter输出到CSV不会触发

时间:2016-02-29 23:02:23

标签: jquery tablesorter

我,在我的生活中,似乎无法让tableorter下载到CSV功能。我想也许我的设置有问题所以我创建了一个裸骨测试表但仍然遇到了同样的问题。

根据official documentation,我需要使用tablesorter 2.8或更高版本(我在2.25.3上)和jQuery 1.7或更高版本(我在jQuery 1.12.0中提取)。我从this question跟随Mottie自己的简单设置,但我没有运气。

以下是我的测试代码。我不得不遗漏一些明显的东西,但是在盯着它看了好几个小时后,我都没有看到它。

<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删掉我自己的[local] tabelsorter脚本src。

1 个答案:

答案 0 :(得分:2)

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

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

应在 tablesorter之后使用<script> 加载。点击&#34;外部资源&#34; this demo的一部分,以查看您需要的所有文件(不包括jQuery)。