dongsi7067 2014-09-01 15:31
浏览 44

如何使用jQuery数据表插件将所有数据导出到CSV文件

I want to export the all the result data to be export in CSV file, As of now only current page data is saving in CSV file in jQuery data table

  • 写回答

1条回答 默认 最新

  • doulubashang6936 2014-09-01 16:01
    关注

    I'm not sure how you want to "export" the data, but you can create the csv contents easily with each() in jQuery. Given your question states that you're using a jQuery data table, you'll already have jQuery imported.

    Here is a simple table and the code to parse the contents into csv format. There is a textarea of whose value we set the final "export" data to.

    <table id="tbl">
        <tr>
            <th>Col1</th><th>Col2</th><th>Col3</th>
        </tr>
        <tr>
            <td>eggs</td><td>bacon</td><td>milk</td>
        </tr>
        <tr>
            <td>free</td><td>tasty</td><td>food</td>
        </tr>
    </table>
    
    <textarea id="output"></textarea>
    
    <script>
    
    $("#output").html(getTableData($("#tbl")));
    
    function getTableData(table) {
        var data = [];
        table.find('tr').each(function (rowIndex, r) {
            var cols = [];
            $(this).find('th,td').each(function (colIndex, c) {
                cols.push(c.textContent);
            });
            data.push(cols + "
    ");
        });
        return data;
    }
    </script>
    

    Note: we use .html() on the textarea instead of .val() to avoid extraneous, prepended commas on each line after the first.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类