Jquery - DataTables [tableTools]: export only visible rows

前端 未结 4 1653
陌清茗
陌清茗 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 02:44

    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);
        });
    } );
    

提交回复
热议问题