Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 962
parrker9 Avatar asked Nov 21 '11 05:11

parrker9


2 Answers

See the following code block, hope it will help you.

$(document).ready( function () {    
    $('#datagridtable').dataTable( {
        "sDom": '<"H"Tfr>tC<"F"ip>',

        "oColVis": {
            "buttonText": "&nbsp;",
            "bRestore": true,
            "sAlign": "right"
        },
        "oTableTools": {
            "sSwfPath": "datagrid/media/swf/copy_csv_xls_pdf.swf",
            "aButtons": [ 
                {'sExtends':'xls',
                    'mColumns':'visible' //set which columns here
                }, 
                {'sExtends':'pdf',
                    'mColumns':'visible' //set which columns here
                },
                {'sExtends':'print',
                    'mColumns':'visible' //set which columns here
                }, ]
        }
    } );
} );
like image 42
Abu Sadat Mohammed Yasin Avatar answered Nov 15 '22 02:11

Abu Sadat Mohammed Yasin


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.

like image 71
dnagirl Avatar answered Nov 15 '22 02:11

dnagirl