Exporting filtered datatable

Exporting filtered datatable

cterracterra Posts: 2Questions: 1Answers: 0
edited June 2016 in Free community support

Hello,

I ve created a datatable filtered with yacdf and then with columnFilter, and in both case, when i am trying to export my datatable to pdf (or other format), my header datatable show me all my filter.

I ve created a topic on stackoverflow : http://stackoverflow.com/questions/37940653/incorrect-header-when-exporting-to-pdf-with-yadcf-filter?noredirect=1#comment63333523_37940653

Here you can see the problem : (attached picture)

(i choose a little datatable for example, but most of my case have more column and more values)
How can i do, to export my datatable without all my filter in the header case ?

Thanks

Answers

  • allanallan Posts: 63,208Questions: 1Answers: 10,415 Site admin

    This is a real limitation / mess in DataTables at the moment I'm afraid. Basically it is just taking the text content of the header cell, which is what you are seeing in the output.

    Currently, to resolve this you would need to use a formatting function with buttons.exportData(): format.header specifically.

    This example shows how you can set a formatting function (although not one that will do specifically what you are looking for).

    Allan

  • cterracterra Posts: 2Questions: 1Answers: 0

    Ok thanks i resolved my case :

    exportOptions: {
    columns: ':visible' ,
    format: {
    header: function ( data, column, row )
    {
    return data.substring(data.indexOf("inline-block")+15,data.indexOf("<span"));
    }
    }
    }

    it exports welll :

    It's pretty weird to add this in all my datatables, maybe you should add it natively with condition in your code.

  • allanallan Posts: 63,208Questions: 1Answers: 10,415 Site admin

    Yes, the next major version of DataTables will include an API for this sort of thing.

    Good to hear you got it working - thanks for posting back.

    Allan

This discussion has been closed.