[reportlab-users] Splitting tables with repeated ROWBACKGROUNDS

156 views
Skip to first unread message

Axel P. Kielhorn

unread,
Mar 21, 2020, 6:55:48 AM3/21/20
to reportl...@lists2.reportlab.com
Hello!

I have some data that I want to put into a table, but it doesn’t fit into one row.
Therefore I split it into two rows and use ROWBACKGROUNDS to group the rows.

This works great until I have to split the table.
(Well reportlab splits the table for me.)

Sometimes, depending on the start position on the page, a table break will occur inside a double row.
This means the grouping on the following page is wrong.

Is there a way to influence the table break?
(Every second (or nth) row)

An alternative would be to SPAN the first column, hoping the table won’t break a SPAN.
But this means I have to track my data and add a TABLESTYLE for each double row.

Right now I simply throw my data at the table and hope for the best.

Please find included an example of what I’m doing right now.

Greetings
Axel


rl-ecm.py

Robin Becker

unread,
Mar 21, 2020, 10:02:14 AM3/21/20
to reportlab-users
Hi Axel,

wasn't quite sure what a double row was, but I guess you just mean that the rows are associated with each other in terms
of background colour.

I think I understand the problem after looking at your example. So logically in your example you want the first two rows
to be a specific background colour and then have the colour alternate between grey and white. Currently the
ROWBACKGROUNDS argument is just a list and to accomplish what you seem to want it needs more structure eg a history of
where in the sequence it is and the rendering needs to know about repeat rows etc etc.

I'll have a think.

On 21/03/2020 10:54, Axel P. Kielhorn wrote:
> Hello!
>
> I have some data that I want to put into a table, but it doesn’t fit into one row.
> Therefore I split it into two rows and use ROWBACKGROUNDS to group the rows.
>

.........

--
Robin Becker
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
https://pairlist2.pair.net/mailman/listinfo/reportlab-users

Axel P. Kielhorn

unread,
Mar 22, 2020, 3:02:25 AM3/22/20
to reportl...@lists2.reportlab.com
Am 21.03.2020 um 15:01 schrieb Robin Becker <ro...@reportlab.com>:
>
> Hi Axel,
>
> wasn't quite sure what a double row was, but I guess you just mean that the rows are associated with each other in terms of background colour.
>
> I think I understand the problem after looking at your example.

I thought it would be easier to test your ideas on something, instead of writing code based on my description.

> So logically in your example you want the first two rows to be a specific background colour and then have the colour alternate between grey and white. Currently the ROWBACKGROUNDS argument is just a list and to accomplish what you seem to want it needs more structure eg a history of where in the sequence it is and the rendering needs to know about repeat rows etc etc.

ROWBACKROUNDS is just a visual representation.
Maybe this is the wrong way round:
- there could be a logical description of some sort of grouping.
- these groupings get different colours.

> I'll have a think.

Thanks.
In the meantime I implemented my suggestion from yesterday and added an empty column with a span.
It works in the test case.

There is one minor issue: The table on page 2 starts with the wrong colour.
Changing the ROWBACKGROUNDS definition fixed that.

Have a nice weekend and stay safe.

Axel

rl-ecm.py

Axel P. Kielhorn

unread,
Mar 22, 2020, 5:06:22 AM3/22/20
to reportl...@lists2.reportlab.com


> Am 22.03.2020 um 08:01 schrieb Axel P. Kielhorn <pyth...@axelkielhorn.de>:
>
>
> In the meantime I implemented my suggestion from yesterday and added an empty column with a span.
> It works in the test case.

And I have to correct myself:

I want to add the span to the Table, not the TableStyle.

bt = Table(bdata, repeatRows=2, colWidths=(None, None, 0))
bt.setStyle(TableStyleLD)

for i in range(0, len(Data), 2):
bt.setStyle([('SPAN', (-1, i), (-1, i+1))])

Greetings
Axel
Reply all
Reply to author
Forward
0 new messages