Jquery - DataTables [tableTools]: export only visible rows

前端 未结 4 1654
陌清茗
陌清茗 2021-02-09 02:18

I just started out using jQuery DataTables.

using the tableTools of DataTables, is it possible to only export visible rows instead of all the rows? If for example the pa

4条回答
  •  再見小時候
    2021-02-09 03:00

    If you are using flash to export, need to mention swf path to work.

    $("#example").dataTable( {
        "sDom": 'T<"clear">lfrtip',
        "oTableTools": {
            "sSwfPath": "Path to your copy_csv_xls_pdf.swf files comes with TableTools",
            "aButtons": [
                {
                    "sExtends": "copy",
                    "sButtonText": "Copy to clipboard",
                    "oSelectorOpts": { filter: "applied", order: "current" }
                },
                {
                    "sExtends": "csv",
                    "sButtonText": "Export to CSV",
                    "oSelectorOpts": { filter: "applied", order: "current" }
                },
                {
                    "sExtends": "print",
                    "sButtonText": "Print",
                    "oSelectorOpts": { filter: "applied", order: "current" }
                }
            ]
        }
    } );
    

    There are few additional options also available to aButtons object.

    "mColumns": [1, 2,...] - List of columns to include in export result
    
    "sTitle": "filename" - desire filename for export file
    

    ------------------Update---------------------------

    In the newer version of datatable - datatableTools is retired

    Please use buttons extension

    buttons: [
            {
                extend: 'copyHtml5',
                exportOptions: {
                    columns: [ 0, ':visible' ]
                }
            },
            {
                extend: 'excelHtml5',
                exportOptions: {
                    columns: ':visible'
                }
            },
            {
                extend: 'pdfHtml5',
                exportOptions: {
                    columns: [ 0, 1, 2, 5 ]
                }
            },
        ]
    

提交回复
热议问题