Export to CSV Header text

Export to CSV Header text

sjw01sjw01 Posts: 67Questions: 36Answers: 1

Example: http://live.datatables.net/lidequra/9/edit

In this example, I am putting the column filter in the head of the table on a few columns.

Problem: When I "Export CSV" - The column headings are all muddled as it is using all the values from the select lists

  1. I am assuming that this is unavoidable? There is no way to set a column header which is used in CSV BUT the filter still remains?

  2. I tried moving the filter to the footer (not ideal but at least a solution) BUT - when I revert the code back to what it originally was, the filters do not show.

Current:
var select = $('<select><option value="">' + $(columnHeaderCell).html() + '</option></select>') .appendTo( $(column.header()).empty() )

Altered for footer() = not working:

var select = $('<select><option value="">' + $(columnHeaderCell).html() + '</option></select>') .appendTo( $(column.footer()).empty() )

Why wont the select show in the footer?

Replies

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin

    What you need to do here is to use a formatting function for the header - specifically the format.header() function (buttons.exportData()).

    That formatting function will let you pick out the data you want from the header cell without the select element. The issue is that using $().text() on the cell (which Buttons does) will include the labels from the select element!

    This is a deficiency that is going to be corrected in future!

    The other option is to have your filtering inputs on a second row in the header.

    Allan

  • sjw01sjw01 Posts: 67Questions: 36Answers: 1

    The second row under the header option would be perfect.
    I didn't know a second header row could be created.
    Are there any guides on how this could best be implemented?

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @sjw01 ,

    This example here discusses options. This here is an example from another thread, which could be used as a template.

    Cheers,

    Colin

This discussion has been closed.