jquery - 使用 DataTables 导出为 PDF 时格式化特定的列内容样式
问题描述
我在我的网站上使用Datatables,并且我试图仅在导出为 PDF 时才将特定列的内容设为粗体。我知道可以使用指定导出选项的这种方法来完成基于简单文本的格式设置,
exportOptions: {
format: {
body: function ( data, row, column, node ) {
// Strip $ from salary column to make it numeric
return column === 5 ?
data.replace( /[$,]/g, '' ) :
data;
}
}
}
但我不明白如何将输出设置为粗体。谢谢你的时间!
解决方案
首先以 JSON 格式转储您的数据表内容。您可以格式化表格中任何单元格的内容。
取自 PDFMake.org 文档
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).print()
推荐阅读
- reactjs - 在 React Native 开发中遇到讨厌的路由请求循环
- php - 如果所选日期超出特定范围,则返回错误的 PHP 表单 - 在 woocommerce 商店中使用 wordpress functions.php
- python - 具有 4 个视觉编码的 Matplotlib 散点图
- reactjs - 何时使用 redux saga 以及何时使用 redux thunk?
- sql - 如何在 SQL 中逐行取两列的平均值?
- python - 来自python的QML画布上的动画元素
- r - 有谁知道为什么饼图在使用 par 函数在 R 中的第四行之后缩小?
- python - 如何从 int64 转换回时间戳或日期时间?
- python - VS Code / Pylance / Pylint 无法解析导入
- swift - 如何在 SWIFT 中打印 Optional Int?