Is it possible to marshal data from an embedded script to the req object?
-
I need to embed a script in my TOC child report so I can identify the vertical offset for the first TOC-row in each page.
The TOC can be multi page and it can also have arbitrary elements before (i.e. won't start at the top of the page). In order to offset the actual page numbers to match the TOC when I merge the second TOC-render I need to get hold of these offsets and insert a correctly sized element before the page numbers for the TOC on each page.
The script might look something like this, but should be refined to just identify the topmost row on each page. I'm having a hard time debugging this since I haven't been able to console.log anything from embedded scripts.
const findPositionsScript = function() { const tocElements = document.querySelectorAll('.toc-content'); return Array.from(tocElements).map(el => el.getBoundingClientRect().top + window.pageYOffset); };
I would like to add the returned array from this script to, for example
req.data.tocPageOffets
. With this information I could offset the pagenumbers on each toc page. Is this possible?edit: clarification..
<script> const findPositionsScript = function() { const tocElements = document.querySelectorAll('.toc-content'); return Array.from(tocElements).map(el => el.getBoundingClientRect().top + window.pageYOffset); }; window.onload = findPositionsScript; IS IT POSSIBLE TO ADD THE RESULT FROM findPositionScript TO THE req.data OBJECT? </script>
Or maybe I could "evaluate" the script from afterRender somehow?
-
So, instead of trying to calculate the offset and try to marchal the data to
req
(which I think is really hard due to the isolation between the browser and Node), I opted for the "render twice" concept as per: https://playground.jsreport.net/w/admin/tV6sVKbVThis is a really neat solution for complex TOC layouts. The drawback is that the complete report has to be rendered twice. I will try to optimize this by rendering empty placeholder divs where I have complex components (such as graphs and complex SVG) and their height is known. Placeholders will only be used in the first render.