How to remove dropdown select options from pdf in datatable

為{幸葍}努か 提交于 2021-01-29 06:42:05

问题


I have included dropdown to each column at footer, while generating pdf,all options are coming into header.how can we exclude these option while export?

Here is my code:

$('#example').DataTable( {
    "dom": 'Bfirtlp',
    buttons: [

            {
            extend: 'excelHtml5',
            exportOptions: {
                columns: ':visible'
            }
            },
        {
            extend: 'pdfHtml5',
            orientation: 'landscape',
            pageSize: 'A3',
            exportOptions: {
                columns: [ 0, 1, 2,3,4,5,6,7,8],

            },
        ],
   initComplete: function () {
        this.api().columns().every( function () {
            var column = this;
             var eachHeader = $(column.header())[0];
             var headingVal = eachHeader.getAttribute("value");
             var select = $('<select class="btn btn-secondary btn-sm dropdown-toggle"><div class="dropdown-menu"><option  class="dropdown-item" value="">'+ headingVal +'</option><div></select>')
                .appendTo( $(column.footer()).empty() )
                .on( 'change', function () {
                    var val = $.fn.dataTable.util.escapeRegex(
                        $(this).val()
                    );

                    column
                        .search( val ? '^'+val+'$' : '', true, false )
                        .draw();
                } );

            column.data().unique().sort().each( function ( d, j ) {
                select.append( '<option value="'+d+'">'+d+'</option>' )
            } );
        } );
    }
} );

回答1:


I got the solutions,

include this,

exportOptions: { 
                format: {
                    header: function ( data, column, row )
                        {
                            return data.substring(data.indexOf("value")+9,data.indexOf("</option"));
                        }
                 }
            },


来源:https://stackoverflow.com/questions/54787333/how-to-remove-dropdown-select-options-from-pdf-in-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!