【问题标题】:Export PDF, CSV, Excel form Datatable using jquery?使用 jquery 导出 PDF、CSV、Excel 表单数据表?
【发布时间】:2018-08-22 21:02:23
【问题描述】:

我正在使用此代码,它运行良好。

但我想从数据表的一行中获取有限的行数据和有限的单词。

我在做什么 Jquery 代码:

if( $('.clienttable').length > 0 ) {
        $('.clienttable').DataTable( {           
            pageLength: 10,
            responsive: true,
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [
                {
                    extend: 'copyHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    }
                },
                {
                    extend: 'csvHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    }
                },
                {
                    extend: 'excelHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    }
                },
                {
                    extend: 'pdfHtml5',
                    exportOptions: {
                        columns: [1, 2, 3,4,5,6]
                    },
                    title: 'List of Clients',
                }
            ],
            columnDefs: [
                { targets: [0], orderable: false },
                { targets: [7], orderable: false }
             ],
            "order": [[ 6, "desc" ]]  
        });
    }

前端代码:

<table class="table table-striped table-bordered table-hover clienttable" >
</table>

其他问题:

excel导出时如何去除列中的空格文本..? 我在 excel 表格单元格中遇到了诸如空格之类的问题,这可以删除空格吗..?

【问题讨论】:

    标签: php jquery laravel datatable


    【解决方案1】:

    您可以使用 DataTables Select 扩展名:DataTables Select

    添加到按钮导出选项:

    modifier: {
          selected: true
    }
    

    select: true
    

    初始化DataTable代码。

    您的新代码:

    if( $('.clienttable').length > 0 ) {
        $('.clienttable').DataTable( {           
            pageLength: 10,
            select: true,
            responsive: true,
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [
                {
                    extend: 'copyHtml5',
                    exportOptions: {
                        columns: [1,2,3,4,5,6],
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                    extend: 'csvHtml5',
                    exportOptions: {
                        columns: [1,2,3,4,5,6],
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                    extend: 'excelHtml5',
                    exportOptions: {
                        columns: [1,2,3,4,5,6],
                        modifier: {
                            selected: true
                        }
                    }
                },
                {
                    extend: 'pdfHtml5',
                    exportOptions: {
                        columns: [1,2,3,4,5,6],
                        modifier: {
                            selected: true
                        }
                    },
                    title: 'List of Clients',
                }
            ],
            columnDefs: [
                { targets: [0], orderable: false },
                { targets: [7], orderable: false }
             ],
            "order": [[ 6, "desc" ]]  
        });
    }
    

    现在您可以只打印选定的行。

    【讨论】:

    • 感谢您的回答...@Zafahix 但不完全符合我的要求
    • @VishvakarmaDhiman 所以你需要一个打印前 50 个结果的函数?
    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多