Nested/Sub Tables with PDFMake

点点圈 提交于 2019-12-25 06:45:45

问题


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.


回答1:


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']
                                                            ]
                                                        },
                                                    }
                                                ]
                                        ]
                                ]
                        }
                },

    ]

}


来源:https://stackoverflow.com/questions/39454842/nested-sub-tables-with-pdfmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!