Jquery - DataTables [tableTools]: export only visible rows

datatables, jquery, tabletools

Solution

You can achieve that behavior by selecting all visible rows before saving, then deselecting them after saving completed.

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'T<"clear">lfrtip',
        "oTableTools": {
            "sRowSelect": "multi",
            "aButtons": [
                {
                    "sExtends": "csv",
                    "bSelectedOnly": true,
                    "fnComplete": function ( nButton, oConfig, oFlash, sFlash ) {
                        var oTT = TableTools.fnGetInstance( 'example' );
                        var nRow = $('#example tbody tr');
                        oTT.fnDeselect(nRow);
                    }
                }
            ]
        }
    } );

    $('a.DTTT_button_csv').mousedown(function(){
        var oTT = TableTools.fnGetInstance( 'example' );
        var nRow = $('#example tbody tr');
        oTT.fnSelect(nRow);
    });
} );

Problem

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 pagination was set to 10 I would expect only 10 rows to be exported. The same goes for a search result. Here's part of the code: ``` $(document).ready(function() { var table = $('#example').DataTable({ "pagingType": "full_numbers", "iDisplayLength" : 10, dom: 'T<"clear">lfrtip', "oTableTools": { "aButtons": [ { "sExtends": "copy", "mColumns": "visible", "bSelectedOnly": true }, { "sExtends": "xls", "mColumns": "visible" }, { "sExtends": "print", "mColumns": "visible" } ], "sRowSelect": "multi"}, "order": [[ 0, "asc" ]] } ) ;... ``` Thank you.

Original source