0

How do I use nested/sub tables with PDFmake? I've tried simply putting in multiple tables but that doesn't automatically repeat the top level table's header for page breaks.

Elijah Lofgren
  • 1,437
  • 3
  • 23
  • 39

2 Answers2

0

This code is a simplified example of using a sub-table. It is adapted from tables section of the pdfmake playground (wasn't easy to find via Google searching).

Paste the following into: http://pdfmake.org/playground.html

// playground requires you to assign document definition to a variable called dd

var dd = {
    content: [

                { text: 'A simple table with nested elements', style: 'subheader' },
                'It is of course possible to nest any other type of nodes available in pdfmake inside table cells',
                {
                        style: 'tableExample',
                        table: {
                                headerRows: 1,
                                body: [
                                        ['Column 1', 'Column 2'],
                                        [
                                                {
                                                        stack: [
                                                                'Let\'s try an unordered list',
                                                                {
                                                                        ul: [
                                                                                'item 1',
                                                                                'item 2'
                                                                        ]
                                                                }
                                                        ]
                                                },
                                                [
                                                    'or a nested table',
                                                    {
                                                        table: {
                                                            body: [
                                                                [ 'Col1', 'Col2', 'Col3'],
                                                                [ '1', '2', '3'],
                                                                [ '1', '2', '3']
                                                            ]
                                                        },
                                                    }
                                                ]
                                        ]
                                ]
                        }
                },

    ]

}
Elijah Lofgren
  • 1,437
  • 3
  • 23
  • 39
0

I need to achieve almost similar functionality like above. I have tried a lot, but not getting it right. How to create a json array that would produce an pdf output using pdfmake? I need to create a table within a table:

var dd = {
  content: [
    {
      text: 'A simple table with nested elements',
      style: 'subheader'
    },
    'It is of course possible to nest any other type of nodes available in pdfmake inside table cells',
    {
      style: 'tableExample',
      table: {
        headerRows: 1,
        body: [
          ['Column 1', 'Column 2'],
          [
            [
              'or a nested table',
              {
                table: {
                  body: [
                    [ 'Col1', 'Col2', 'Col3'],
                    [ '1', '2', '3'],
                    [ '1', '2', '3']
                  ]
                },
              }
            ]
          ]
        ]
      }
    },
  ]
}
fcdt
  • 2,371
  • 5
  • 14
  • 26
Anoop P S
  • 754
  • 1
  • 12
  • 31