我已经去过这个线程Set Column width when exporting to pdf when using datatables net但它已经快一年了,并没有解决我的问题。我想在以 pdf 格式导出 DataTable 时调整我的列的列宽。我试过这个,但没有任何改变:
$('#table').dataTable({
"dom": '<"top"f>tiB',
paging: false,
fixedHeader: {headerOffset: 45},
buttons: [
{
extend: 'pdfHtml5',
exportOptions: {
columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
},
customize : function(doc) {
doc.styles['td:nth-child(8)'] = {
width: '1000px',
'max-width': '1000px'
}
},
text: 'Export: PDF',
orientation: 'landscape',
pageSize: 'A3',
}]
});
Run Code Online (Sandbox Code Playgroud)
包含 pdfmake.js,我也尝试过width: 1000或"width: 1000"类似的东西。