Reputation: 374
Is there a function / setting for printing ReactVirtualized Lists? I want to either print the whole content of the list (the rows are lazy loaded but maybe someone knows how to do it) or print what fits in a page without having to set the pixel dimensions.
I looked up the docs and couldn't find anything.
Thanks.
Upvotes: 2
Views: 1864
Reputation: 786
I've found a way to do it using the above solution with media-query, css-vars and the overscanRowCount
property. (sounds a lot, but it is actually very short)
... I used css modules, but it can be done in pure css. ... I hope this is clear enough
if (printMode) {
window.requestAnimationFrame(() => {
//requestAnimationFrame is important because window.print is an async function
window.print();
})
}
.paper123 {
height: 400px;
width: 100%
}
@media print {
.paper123 {
height: var(--mh) !important; /*the calculated height passed as css-var */
width: 100%
}
:global(.ReactVirtualized__Grid) {
margin: none !important;
overflow: visible !important;
display: block;
height: auto !important;
}
}
/* React code */
<div >
<Paper className={style.paper123} style={{ "--mh": 48 * (rows.length + 1) + 'px' }}>
< VirtualizedTable
rowCount={rows.length}
rowGetter={({ index }) => rows[index]}
columns={columns}
overscanRowCount={!printMode ? 40 : rows.length} //overscanRowCount property means that you can define the max number of rows prerendered in the virtualized-table
/>
</Paper >
</div>
Upvotes: 1
Reputation: 1203
I had a similar problem some month ago and I ended up making it work with a print button that runs a function that changes the CSS to display the entire list on the page (i.e: removed the scrolling) and then reload the list in full.
.ReactVirtualized__Grid {
margin: none !important;
overflow: visible !important;
display: block;
height: auto !important; //OR PUT A HUGE AMOUNT WHERE YOUR LIST WILL ALWAYS FIT (9999999px)
}
There might be a cleaner way to do it but I did not find any and that worked out fine for what I needed.
Upvotes: 2