将一列与pdfmake和datatables对齐 [英] Align one column with pdfmake and datatables
本文介绍了将一列与pdfmake和datatables对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用动态生成的mysql表和数据表将1列与PDFMAKE中心的其他列左对齐,如果禁用分页,我使用的代码将起作用,但是使用分页时,它只能证明显示的前25行是合理的屏幕上有什么主意吗?
Trying to align 1 column to the left with the other columns centered in PDFMAKE using a dynamically generated mysql table and datatables, the code i have works if you disable pagination, but with pagination it only justify's the first 25 rows that are displayed on the screen, any ideas?
$(document).ready(function() {
$("#loops").DataTable( {
dom:
"<'row'<'col-sm-3'l><'col-sm-6 text-center'B><'col-sm-3'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
buttons: [
{
extend: 'pdfHtml5',
pagesize: 'A3',
text: 'Export to PDF',
orientation: 'landscape',
customize: function (doc) {
var rowCount = document.getElementById("loops").rows.length;
for (i = 0; i < rowCount+1; i++) {
doc.content[1].table.body[i][5].alignment = 'left';
};
doc.styles.tableHeader.fontSize = 7;
doc.defaultStyle.fontSize = 7;
doc.content[1].table.widths = [60, 100, 70, 70, 60, '*', 90, 20, 20]
doc.styles.tableBodyEven.alignment = 'center';
doc.styles.tableBodyEven.noWrap = true;
doc.styles.tableBodyOdd.alignment = 'center';
doc.styles.tableBodyOdd.noWrap = true;
doc.styles.tableBodyOdd.fillColor = '#f3f3f3';
},
},
'copy', 'excel'
]
} );
} );
推荐答案
通过如下更改代码来解决此问题
Solved this by changing the code as follows
var rowCount = doc.content[1].table.body.length;
for (i = 0; i < rowCount+1; i++) {
doc.content[1].table.body[i][5].alignment = 'left';
};
上面的代码会将第五列更改为左对齐.如果您想让标题居中使用
the above code will change the fifth column to left justified. If you want to leave the header centered use
var rowCount = doc.content[1].table.body.length;
for (i = 1; i < rowCount; i++) {
doc.content[1].table.body[i][5].alignment = 'left';
};
这篇关于将一列与pdfmake和datatables对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文