Export specific columns from datatables using column header

Export specific columns from datatables using column header

v3nkyv3nky Posts: 46Questions: 11Answers: 0

Is it possible to export specific columns from datatables using column header instead of column index?

Below is example using column index.

{ extend: 'excel', text: 'Exportieren InfoDatei (xls/xlsx)',title:'BerichtInfo_Datei_Export',
exportOptions: {
columns: [1,2,3,4,5,6,7,9,66,67,30,26,68,28]

                    },
                   filename: function(){
                      var date = new Date();
                     var n = date.getFullYear() + "" + (date.getMonth()+01) + "" + date.getDate() + "" +  date.getHours() + "" + date.getMinutes() + "" + date.getSeconds();
                      return 'BerichtInfo_Datei_Export_' + n;
                  }

Instead I would like to use column names. Please advise how can I use column names.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,171Questions: 1Answers: 2,589

    Hi @v3nky ,

    This example here shows the export options, and shows that the columns can be specified by the column-selector. This section here shows how to use the column names.

    Hope that helps,

    Cheers,

    Colin

  • v3nkyv3nky Posts: 46Questions: 11Answers: 0
    edited October 2018

    `{ extend: 'excel', text: 'Exportieren InfoDatei (xls/xlsx)',title:'BerichtInfo_Datei_Export',
    exportOptions: {
    /* columns: [1,2,3,4,5,6,7,9,66,67,30,26,68,28] */
    columns :[
    {name:"REPORTING_ID"}
    ]

                        },
                       filename: function(){
                          var date = new Date();
                         var n = date.getFullYear() + "" + (date.getMonth()+01) + "" + date.getDate() + "" +  date.getHours() + "" + date.getMinutes() + "" + date.getSeconds();
                          return 'BerichtInfo_Datei_Export_' + n;
                      }`
    

    I have tried this but did not work.

  • kthorngrenkthorngren Posts: 20,393Questions: 26Answers: 4,786
    Answer ✓

    Here is an example using the links that Colin provided.
    http://live.datatables.net/japeyavu/1/edit

    Looks like the columns listed in you exportOptions is not the correct format. Also did you set the columns.name option as shown in Colin's second link?

    Kevin

  • v3nkyv3nky Posts: 46Questions: 11Answers: 0

    Thank you kthorngren . I have corrected columns naming format in export options and then it worked. Thank you once again.

This discussion has been closed.