E
E
EvgenJunior2021-10-23 12:27:58
JavaScript
EvgenJunior, 2021-10-23 12:27:58

How to stretch a nested table to the full width of a cell in the pdfMake.js library?

Good afternoon! I need to generate a report in pdf format. For this I use the pdfmake.js library. The report consists of tables, nested tables. The difficulty arose in the following: I can not stretch the nested table to the entire height of the cell.
Thanks in advance for the tip.
PS the project is being done on React.js

const docDefinition: TDocumentDefinitions = {
    pageOrientation: 'landscape',
    pageSize: 'A4',
    content: [
      {
        text: '1.1.1 Text',
        style: 'header'
      },
      'Text',
      {
        style: 'tableExample',
        table: {
          dontBreakRows: true,
          widths: ['17.5%', '17.5%', '17.5%', '17.5%', '30%'],
          body: [
            [
              { text: 'Text text Text text Text text Text text Text text Text text Text textText text Text text Text text', alignment: 'center' },
              { text: 'Text text', alignment: 'center' },
              {
                text: 'Text text',
                alignment: 'center'
              },
              {
                text: 'Text text',
                alignment: 'center'
              },
              {
                style: 'titleInnerTable',
                table: {
                  widths: ['33.33%', '33.33%', '33.33%'],
                  body: [
                    [
                      {
                        text: 'Text',
                        colSpan: 3,
                        alignment: 'center'
                      },
                      {},
                      {}
                    ],
                    ['Text', 'Text', 'Text']
                  ]
                },
                layout: {
                  hLineWidth(i, node) {
                    return i === 0 || i === node.table.body.length ? 2 : 1;
                  }
                }
              }
            ],
            [
              {
                text: 'text1',
                alignment: 'center'
              },
              'text2',
              'text3',
              'text4',
              {
                table: {
                  widths: ['33.33%', '33.33%', '33.33%'],
                  heights: ['50%', '50%'],
                  body: [
                    [
                      {
                        text: 'Text'
                      },
                      {
                        text: 'Text'
                      },
                      {
                        text: ''
                      }
                    ],
                    [
                      {
                        text: 'Text'
                      },
                      {
                        text: 'Text'
                      },
                      {
                        text: ''
                      }
                    ]
                  ]
                },
                layout: {
                  hLineWidth(i, node) {
                    return i === 0 || i === node.table.body.length ? 0 : 1;
                  },
                  vLineWidth(i) {
                    return 0;
                  }
                }
              }
            ]
          ]
        }
      }
    ],
    styles: {
      tableExample: {
          fontSize: 18,
      bold: true,
      margin: [0, 0, 0, 0]
      },
      titleInnerTable: {
          fontSize: 16,
      bold: true,
      margin: [0, 0, 0, 0]
      }
    }
  };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question