【问题标题】:Format particular column content style when exporting to PDF using DataTables使用 DataTables 导出为 PDF 时格式化特定的列内容样式
【发布时间】:2018-11-30 05:27:35
【问题描述】:

我在我的网站上使用Datatables,并且我试图仅在导出为 PDF 时将特定列的内容设为粗体。我知道可以在指定导出选项的using this method 处完成基于简单文本的格式设置,

exportOptions: {
        format: {
            body: function ( data, row, column, node ) {
                // Strip $ from salary column to make it numeric
                return column === 5 ?
                    data.replace( /[$,]/g, '' ) :
                    data;
            }
        }
    }

但我不明白如何将输出设置为粗体。感谢您的宝贵时间!

【问题讨论】:

    标签: jquery css datatables pdf-generation pdfmake


    【解决方案1】:

    首先以 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 2015-04-28
      • 1970-01-01
      • 2014-07-26
      相关资源
      最近更新 更多