0

So basically, my table has a bunch of sub-headers and I want a page break to be inserted after so many of these subsections and prevent an automatic page break in the middle of one of the sections. It looks this roughly. The gray areas are the sub-headers where a page break would be before if it was like the 4th, 8th, 12th, etc. subsection.

table

There are two main issues I am running into which may or may not be unique to React. Also, I am using Bootstrap.

1) The <div> as a child of <table>, <tbody>, <thead> issue:

My initial thinking was to just insert <div className='pagebreak'> after every 4th <th>. This will trigger the error (paraphrased) as a <div> cannot be a child of <table>/<tbody>/<thead>.

So doing something like the following is not permitted:

let i = 1;

return _.map(section, s => {
    i++;
    return (
        <table>
            <tbody>
                <tr>
                    <th colSpan='6'>{s.subSectionTitle}</th>
                </tr>
                <tr>
                    <td>{s.data1}</td>
                    <td>{s.data2}</td>
                    <td>{s.data3}</td>
                    <td>{s.data4}</td>
                    <td>{s.data5}</td>
                    <td>{s.data6}</td>
                </tr>
                { i = 4 ? <div className='pagebreak'></div> : null }
            </tbody>
        </table>
    )
})

A few other bright ideas I had that didn't work was to do something like:

{ i = 4 ? <tr className='pagebreak'></tr> : null }

Or:

{ i = 4 ? <th><td className='pagebreak'></th></tr> : null }

Or:

{ i = 4 ? <tr><th><div className='pagebreak'></div></th></tr> : null }

While these will get around there error, they don't do anything. It will ignore the pagebreak

It seems like you cannot put any kind of page break inside of a <table> tag.

2) Creating a new <table> for every subsection.

It will just look like crap because column widths will vary from table to table unless I make the widths static which I don't want to do. Want to keep them dynamic while having all the columns widths be the same through out, which is determined by the max width of a data point within a given column.

That being said, this does work in that it actually inserts a page break:

    return (
        <table>
            <tbody>
                <tr>
                    <th colSpan='6'>{s.subSectionTitle}</th>
                </tr>
                <tr>
                    <td>{s.data1}</td>
                    <td>{s.data2}</td>
                    <td>{s.data3}</td>
                    <td>{s.data4}</td>
                    <td>{s.data5}</td>
                    <td>{s.data6}</td>
                </tr>
            </tbody>
        </table>
        <div className='pagebreak'></div>
        <table>
            <tbody>
                <tr>
                    <th colSpan='6'>{s.subSectionTitle}</th>
                </tr>
                <tr>
                    <td>{s.data1}</td>
                    <td>{s.data2}</td>
                    <td>{s.data3}</td>
                    <td>{s.data4}</td>
                    <td>{s.data5}</td>
                    <td>{s.data6}</td>
                </tr>
            </tbody>
        </table>   
    )

Any suggestions for how to handle this?

cjones
  • 8,384
  • 17
  • 81
  • 175
  • `
    ` also I think that you should return all within a single wrapper element, not two tables and a DIV
    – Roko C. Buljan May 06 '18 at 22:12
  • Fixed the tag. That is what I would like to do, preferably in the middle of the `