Search code examples
jquerydatatablesexport-to-excel

jQuery DataTables: exporting individual columns to Excel


On a web page I am displaying a list of topics created by the website users with only their titles listed. I can export to excel the whole table using TableTools and it works fine. However, some of the columns are not required, and I would like to hide some of them somehow. In a perfect situation I would like to display a small popup window when a user clicks the "XLS" button, with several checkboxes with respective table headers and a button "Export". This way the user can select only the necessary data for export. Can someone direct me, please?

  1. Is it possible to export individual columns to Excel in jQuery DataTables?
  2. Is it possible to export a column that was previously hidden using the fnSetColumnVis function?

Solution

  • When you define your buttons in oTableTools, you can set which columns to export:

    "oTableTools":{
        'aButtons':[
            {'sExtends':'xls',
             'mColumns':[1,2,7,23] //set which columns here
            },
            {'sExtends':'pdf',
             'mColumns':'visible' //set which columns here
            },
                                    ]
    }
    

    The docs are here.