question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exporting PDF yadcf table

See original GitHub issue

Hello,

I am trying to export pdf from a table that I’ve created with yadcf however the sub values of multiple select in header also exports to pdf.

$(document).ready(function () {
    $('#yadcf').dataTable(
        {
            dom: 'Bfrtip',
            "iDisplayLength": 100,
            buttons: [
                {
                    extend: 'print',

                },
                'excel',
                {
                    extend: 'pdfHtml5',
                    orientation: 'landscape',
                    pageSize: 'LEGAL',
                    "bHeader": false //<-- THIS

                },
            ],

            "columnDefs": [
                {
                    "orderData": [1, 0], "targets": 0,},
                {header:"", className: "dt-head-center","target": "_all"  },
                {className: "dt-body-center" ,"targets": "_all"     },
            ],

        }
    ).yadcf([
        {column_number: 0},
        {column_number: 1},
        {column_number: 2},
        {column_number: 8},
    ]);
});

Here are some screenshots.

screen shot 2016-02-10 at 11 29 52 screen shot 2016-02-10 at 11 30 00

thank you !

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
bambitacommented, Feb 15, 2016

Thanks. Yes, you are right. I was able to exclude yadcf filters (html, div) from exported headers. Not sure if it is nice way but it works for me.

My working export button definition is

{
    extend : 'excel',
    exportOptions : {
        columns : ':visible',
        format : {
            header : function (mDataProp, columnIdx) {
                var htmlText = '<span>' + mDataProp + '</span>';
                var jHtmlObject = jQuery(htmlText);
                jHtmlObject.find('div').remove();
                var newHtml = jHtmlObject.text();
                console.log('My header > ' + newHtml);
                return newHtml;
            }
        }
    }
}
1reaction
TauPancommented, Dec 11, 2020

Thanks. Yes, you are right. I was able to exclude yadcf filters (html, div) from exported headers. Not sure if it is nice way but it works for me.

My working export button definition is

{
    extend : 'excel',
    exportOptions : {
        columns : ':visible',
        format : {
            header : function (mDataProp, columnIdx) {
                var htmlText = '<span>' + mDataProp + '</span>';
                var jHtmlObject = jQuery(htmlText);
                jHtmlObject.find('div').remove();
                var newHtml = jHtmlObject.text();
                console.log('My header > ' + newHtml);
                return newHtml;
            }
        }
    }
}

Hm, somewhere I found this for “copy to clipboard” and “csv export options” and have been using it for a while now and it still works with yadcf:

  exportOptions : {
      columns : ':visible',
      header:
      (innerHtml, col_index, cell_node) => {
        return cell_node.childNodes[0].nodeValue;
      }
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect header when exporting to PDF with yadcf filter
When I am trying to export to pdf my Datatable with a filter yadcf, the header show always every case from my filter,...
Read more >
PDF button, column header showing 'x' - from yadcf column ...
What is happening (picture 2) is that when you export the grid using cvs or pdf.. it shows that 'x' beside the title....
Read more >
Powerful jQuery Data Table Column Filter Plugin - yadcf
With this plugin, you can add various types of filters to each column of your data table. Licensed under the both GPL and...
Read more >
Jquery Datatable Tutorial | How to add Copy | Excel | PDF Button
Learn how to add How to add Copy | Excel | PDF Button in Jquery Datatable Plugin. Datatable File export : Exporting data...
Read more >
Jquery Datatable Add Button To Each Row
Yet Another DataTables Column Filter - (yadcf) Description: This jQuery a ... Note: Exporting a table as a list does not create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found