在使用datatables.net时导出为pdf时设置列宽
我有这个表,我想导出,但一列的宽度是这么长的时间内容是短的,它使布局不好看,当它导出到pdf im使用datatables.net的代码导出时,这里是我的代码
hi i have this table that i wanted to export but the width of one column is so long when the content is only short and it makes the layout not looking good when it is exported to pdf im using the codes from datatables.net when exporting and here is my code
$(document).ready(function() {
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var d = day + "-" + month + "-" + year;
$('#detailTable').DataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'excelHtml5',
title: d + ' Purchase Orders'
}, {
extend: 'csvHtml5',
title: d + ' Purchase Orders'
}, {
extend: 'pdfHtml5',
title: d + ' Purchase Orders',
orientation: 'landscape',
pageSize: 'LEGAL',
exportOptions: {
columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}
}]
});
});
有没有办法可以设置特定列的宽度?感谢提前
is there a way where i can set the width of a specific column? thanks in advance
您可以使用自定义
回调来更改PDFmakes '风格字典。如果要强制#2列为宽度为 100px
或max 100px
,请执行以下操作:
You can use the customize
callback to alter PDFmakes' "style dictionary". If you want to force the #2 column to be 100px
or max 100px
in width, do this :
{
extend: 'pdfHtml5',
title: d + ' Purchase Orders',
orientation: 'landscape',
pageSize: 'LEGAL',
exportOptions: {
columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
},
//--------------------------
customize : function(doc) {
doc.styles['td:nth-child(2)'] = {
width: '100px',
'max-width': '100px'
}
}
}
将通过CSS样式规则
td:nth-child(2) {
width: 100px;
max-width: 100px;
}
到PDFmake。请参阅文档 - > http://pdfmake.org/#/gettingstarted 转到样式字典部分
to PDFmake. See the documentation -> http://pdfmake.org/#/gettingstarted go for section "Style dictionaries"