我正在使用PDF make创建PDF客户端。 PDFMake
使用以下格式来生成PDF
var docDefinition = {
content: [
{
table: {
// headers are automatically repeated if the table spans over multiple pages
// you can declare how many rows should be treated as headers
headerRows: 1,
widths: ['*', 'auto', 100, '*'],
body: [
['first', 'second', 'third', 'the last one'],
['value 1', 'value 2', 'value 3', 'value 4'],
[{ text: 'bold value', bold: true }, 'val 2', 'val 3', 'val 4'] ]
}
}
]
};
pdfMake.createPdf(docDefinition).download('optionalName.pdf');
使用上述格式,我能够成功创建PDF,但是当我尝试动态提供如下所示代码的值时,出现JavaScript runtime error: Malformed table row, a cell is undefined.
var body = [];
var dataRow = [];
var aaa = $('#dataGrid').jqGrid('getRowData').map(function (o) {
for (k in o) {
dataRow.push(o[k]);
}
body.push(dataRow);
});
并在对象传递格式下方
var docDefinition = {
content: [
{
table: {
// headers are automatically repeated if the table spans over multiple pages
// you can declare how many rows should be treated as headers
headerRows: 1,
widths: ['*', 'auto', 100, '*'],
body: [
['ACTIVE', 'DESCRIPTION', 'STUDENT_ID', 'STATUS', 'TYPE'],
body
]
}
}
]
};
所需格式和我的地方有什么问题?请提出建议。谢谢
答案 0 :(得分:0)
您需要在body
变量中包含标题行。因此,您无需使用var body = []
来初始化它:
var body = [ ['ACTIVE', 'DESCRIPTION', 'STUDENT_ID', 'STATUS', 'TYPE'] ];
然后在使用它时,只需使用body
:
// ...
table: {
headerRows: 1,
widths: ['*', 'auto', 100, '*'],
body: body
}
// ...