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

horizontalPageBreakRepeat column page break is going to last page, should happen in the next page. #1011

Open
hselvaraj opened this issue Nov 27, 2023 · 3 comments

Comments

@hselvaraj
Copy link

hselvaraj commented Nov 27, 2023

#horizontalPageBreakRepeat

When there is column is break, the breaking other columns suppose to come in the next page but it's going to the last page.
When we have more than 200 rows column should break and come in the next page, that's how it should be then only it will be easy to refer the column in the next page.

Please check the demo.
https://codepen.io/hari-designer/pen/OJdQrLx?editors=1010

@simonbengtsson
Copy link
Owner

That would make sense to me. Possibly introduced as an option instead of by default to keep backwards compatibility.

simonbengtsson pushed a commit that referenced this issue Dec 5, 2023
Allowing the user to choose how to have horizontal page breaks
Adressing issue #1011
@lucaslm
Copy link

lucaslm commented Dec 5, 2023

I've noticed the plugin is still not working all that well with both footers and Horizontal Page.

Take a look, for instance, on the following two examples, copied from the usual examples, sligthly changed to use both options of horizontalPageBreakBehaviour and footers:

Using horizontalPageBreakBehaviour = 'afterAllRows', which is the default unchanged behaviour


  var head = headRows()
  head[0].region = 'Region'
  head[0].country = 'Country'
  head[0].zipcode = 'Zipcode'
  head[0].phone = 'Phone'
  head[0].datetime = 'DateTime'
  head[0].text = 'Text'
  var body = bodyRows(50)
  body.forEach(function (row) {
    row['text'] = faker.lorem.sentence(10)
    row['zipcode'] = faker.address.zipCode()
    row['country'] = faker.address.country()
    row['region'] = faker.address.state()
    row['phone'] = faker.phone.phoneNumber()
    row['datetime'] = faker.date.recent()
  })

  doc.text('Split columns across pages if not fit in a single page, showing all the columns first', 14, 20)
  doc.autoTable({
    head: head,
    body: body,
    foot: head, // FOOTER WAS ADDED
    foot: head,
    startY: 25,
    // split overflowing columns into pages
    horizontalPageBreak: true,
    horizontalPageBreakBehaviour: 'afterAllRows',
    // repeat this column in split pages
  })
  return doc

We get the following result
document_horizontalPageBreakBehaviour_afterAllRows.pdf

image

Using horizontalPageBreakBehaviour = 'immediately', which is the new behaviour


  var head = headRows()
  head[0].region = 'Region'
  head[0].country = 'Country'
  head[0].zipcode = 'Zipcode'
  head[0].phone = 'Phone'
  head[0].datetime = 'DateTime'
  head[0].text = 'Text'
  var body = bodyRows(50)
  body.forEach(function (row) {
    row['text'] = faker.lorem.sentence(10)
    row['zipcode'] = faker.address.zipCode()
    row['country'] = faker.address.country()
    row['region'] = faker.address.state()
    row['phone'] = faker.phone.phoneNumber()
    row['datetime'] = faker.date.recent()
  })

  doc.text('Split columns across pages if not fit in a single page, showing all the columns first', 14, 20)
  doc.autoTable({
    head: head,
    body: body,
    foot: head, // FOOTER WAS ADDED
    foot: head,
    startY: 25,
    // split overflowing columns into pages
    horizontalPageBreak: true,
    horizontalPageBreakBehaviour: 'immediately',
    // repeat this column in split pages
  })
  return doc

We get the following result

document_horizontalPageBreakBehaviour_imediatelly.pdf

image

As we can see, the footer gets printed twice when the page breaks horizontally. This is because of the following reason.
The function printTableWithHorizontalPageBreak iterates the columns/rows making every horizontal page break, by calling the function addPage (lines 100, 120 and 140), and then calling the function printFoot accordingly (lines 107, 131 and 151).
However addPage already checks to see wheter to print the footer, and when it does we get the repetiion.
I've attempted to address this issue by suppressing the footer on addPage, which is supposed to happend only this time. See the pull request 1013

@lucaslm
Copy link

lucaslm commented Dec 5, 2023

Should I open a new issue for that?

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

3 participants