Incorrect header when exporting to PDF with yadcf filter

随声附和 提交于 2019-12-02 10:52:53

问题


When I am trying to export to pdf my Datatable with a filter yadcf, the header show always every case from my filter, how can I hide that?

My javascript is :

var vsan = $('#vsan').DataTable( {
    "lengthMenu": [ [-1, 10, 40, 50], ["All", 10, 40, 50] ],
    "sDom": '<"top"i>fBltif',    
    "buttons": [
        { 
            extend: 'print',
            exportOptions: {
                columns: ':visible'
            }
        },
        {
            extend: 'excel',
            exportOptions: {
                columns: ':visible'
            }
        },
        {
            extend: 'pdfHtml5',
            exportOptions: {
                columns: ':visible'
            }
        },
        {
            extend: 'copyHtml5',
            exportOptions: {
                columns: ':visible'
            }
        },
        {
            extend: 'csv',
            exportOptions: {
                columns: ':visible'
            }
        }
    ],
    "bJQueryUI": true,  //Enable jQuery UI ThemeRoller support
    "bAutoWidth": false,
    "bDestroy": true,
    //"order": [[ 3, "desc" ]], //tri par défaut
    "bStateSave": false, //plante ?
    "bPaginate": true, //Enable or disable pagination.
    "bInfo": true,
});

yadcf.init(vsan, [{column_number : 0, filter_type : "none"}, {column_number : 1, filter_type : "none"}, {column_number : 2, filter_type : "none"}, {column_number : 3, filter_type : "select"}, {column_number : 4, filter_type : "auto_complete"}, {column_number : 5, filter_type : "range_number_slider"},{column_number : 6, filter_type : "none"}, {column_number : 7, filter_type : "range_number_slider"}]);

Here is the problem :

i'm using :

http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js
https://rawgit.com/vedmack/yadcf/8e071af195106fa702f942373c65164b89ca40ff/jquery.dataTables.yadcf.js

Thanks


回答1:


Ok i did it, but i think it s very weird :

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

I don't know if is it to me to patch that, or maybe there is a bug, but the point is that it works !




回答2:


I too faced this issue and I did something like below:-

exportOptions: { 
columns: ':visible' , 
format: { 
          header: function ( data, column, row ) 
            {
              return data.split('<')[0]; 
            }
       }
}

It worked for me. This will remove the div which is getting added. When I checked my header data was something like: -

column name<div id="yadcf-filter-wrapper--crime_table-7" class="yadcf-filter-wrapper"><select id="yadcf-filter--crime_table-7" class="yadcf-filter " onchange="yadcf.doFilter(this, '-crime_table', 7, 'contains');" onkeydown="yadcf.preventDefaultForEnter(event);" onmousedown="yadcf.stopPropagation(event);" onclick="yadcf.stopPropagation(event);"><option value="-1">Select Column</option>............................<button type="button" id="yadcf-filter--crime_table-7-reset" onmousedown="yadcf.stopPropagation(event);

So I split the div from the column name and kept just the header.



来源:https://stackoverflow.com/questions/37940653/incorrect-header-when-exporting-to-pdf-with-yadcf-filter

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