Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page break within a table component #2730

Open
mpsbhat opened this issue May 31, 2024 · 3 comments
Open

Page break within a table component #2730

mpsbhat opened this issue May 31, 2024 · 3 comments

Comments

@mpsbhat
Copy link

mpsbhat commented May 31, 2024

Namaste,

I'm checking some conditions to have a pagebreak within a table after a particular row count. Below is a sample code for the reference.

        var dd = {
                  content: [
                      {
                          table: {
                              dontBreakRows: true,
                              headerRows: 0,
                              body: [
                                  ['row Header', 'column B'],
                                  ['row 1', 'column B'],
                                  ['row 2', 'column B'],
                                  ['row 3', 'column B'],
                                  [{text: '', pageBreak: 'after'}, ''],
                                  ['row 4', 'column B'],
                                  ['row 5', 'column B']
                              ]
                          }
                      },
                  ]
              }

In the above sample when i comment headerRows: 1, in table definition then it breaks the table to next page as expected. But when headerRows: 1, is enabled then there is an extra blank page appends soon after breaking the table to next page. Any possibilities to handle this case to avoid the extra blank page?

@AlliedComputing
Copy link

Having the same problem here. Any update on this?

@olafur-palsson
Copy link

olafur-palsson commented Sep 16, 2024

@mpsbhat Page with tables are pretty tricky in this library and don't break rows has uncovered edge cases. I've personally not had a lot of success with dontBreakRows and instead use a workaround to get stable page splitting based on whether content fits on page. Not sure if this helps though.

Other notes on quirks:

  • Empty strings "" don't get rendered but single space does " ".
  • pageBreak: 'before' will break before the unrendered text node instead of before the table row.

What's could be happening is that the second column is getting rendered, then page-break, then the left column but since it's "bigger than one page" it renders a whole extra page.

Try putting spaces in and another header row after the page break and see if it works for you.

        var dd = {
                  content: [
                      {
                          table: {
                              dontBreakRows: true,
                              headerRows: 0,
                              body: [
                                  ['row Header', 'column B'],
                                  ['row 1', 'column B'],
                                  ['row 2', 'column B'],
                                  ['row 3', 'column B'],
                                  [{text: ' ', pageBreak: 'after'}, ' '],
                                  ['row Header', 'column B'],
                                  ['row 4', 'column B'],
                                  ['row 5', 'column B']
                              ]
                          }
                      },
                  ]
              }

Here's my workaround for reference.

#1159 (comment)

@mpsbhat
Copy link
Author

mpsbhat commented Sep 26, 2024

@olafur-palsson Namaste,

As mentioned in my comment itself, the code works even if there is no space in the case of headerRows: 0 but it adds an extra page for headerRows: 1

Screenshots attached for reference.

Screenshot from 2024-09-26 12-21-20
Screenshot from 2024-09-26 12-21-10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants