Search code examples
tabletoolsdatatables-1.10

Datatables tabletools copy filtered data


I would like to copy only filtered data from the tabletools plugin. I have seen this question asked a few times and all the answers say to use oSelectorOpts. I believe I am doing this however it doesn't appear to be working.

$(document).ready(function() {
            var oTable = $('#SensorData').DataTable(
            {
                "order": [[2, "desc"]],
                dom: 'T<"clear">lfrtip',
                tableTools: {
                    "sSwfPath": "assets/swf/copy_csv_xls_pdf.swf"
                },
                "oTableTools": {
                    "aButtons": [
                        {
                            'sExtends': 'copy',
                            "oSelectorOpts": { filter: 'applied', order: 'current', page: 'all' },
                        },
                        {
                            'sExtends': 'xls',
                            "oSelectorOpts": { filter: 'applied', order: 'current' },
                        },
                        {
                            'sExtends': 'print',
                            "oSelectorOpts": { filter: 'applied', order: 'current' },
                        },
                        {
                            'sExtends': 'pdf',
                            "oSelectorOpts": { filter: 'applied', order: 'current' },
                        },
                        {
                            'sExtends': 'csv',
                            "oSelectorOpts": { filter: 'applied', order: 'current' },
                        }
                    ]
                },
                "columnDefs": [
                    {
                        "targets": [0],
                        "visible": false,
                        "searchable": false
                    }
                ]
            });

Solution

  • Finally figured this out. I had the abuttons part in the wrong area.

    var oTable = $('#SensorData').DataTable(
                {
                    "bServerSide": false,
                    "order": [[2, "desc"]],
                    dom: 'T<"clear">lfrtip',
                    tableTools: {
                        "sSwfPath": "assets/swf/copy_csv_xls_pdf.swf",
                        "aButtons": [
                            {
                                "sExtends": "copy",
                                "mColumns": [1, 2],
                                "oSelectorOpts": { filter: "applied", order: "current" }
                            },
                            {
                                'sExtends': 'xls',
                                "mColumns": [1, 2],
                                "oSelectorOpts": { filter: 'applied', order: 'current' }
                            },
                            {
                                'sExtends': 'print',
                                "mColumns": [1, 2],
                                "oSelectorOpts": { filter: 'applied', order: 'current' }
                            },
                            {
                                'sExtends': 'pdf',
                                "mColumns": [1, 2],
                                "oSelectorOpts": { filter: 'applied', order: 'current' }
                            },
                            {
                                'sExtends': 'csv',
                                "mColumns": [1, 2],
                                "oSelectorOpts": { filter: 'applied', order: 'current' }
                            }
                        ]
                    },
                    "columnDefs": [
                        {
                            "targets": [0],
                            "visible": false,
                            "searchable": false
                        }
                    ]
                });