Hello,
I am currently trying to print a RadzenDataGrid along with its styles and most of them aren't there when printing.
The Grid I am trying to print :
The render I get when printing :
I have tried adding styles througth a print.js file wich allow me to print the component I want to but without most of its styles.
print.js file :
// print.js
function printComponent(componentSelector, styles) {
var elementToPrint = document.querySelector(componentSelector);
if (elementToPrint) {
var printWindow = window.open('', '_blank');
printWindow.document.open();
printWindow.document.write('<html><head>');
printWindow.document.write(styles)
printWindow.document.write('<title>Print pochette</title></head><body>');
printWindow.document.write(elementToPrint.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
printWindow.close();
}
}
print method in component file :
<style>
:root {
--rz-grid-header-color: white;
--rz-grid-header-font-size: 14px;
--rz-grid-header-font-weight: bold;
--rz-grid-font-size: 20px;
}
.rz-grid-table {
width: unset;
text-align: center;
}
.rz-grid-table th {
text-align: center;
}
</style>
<Button Color="ButtonColor.Success" @onclick="@(() => PrintComponent("controleOF"))">Imprimer</Button>
<RadzenDataGrid @ref="OFsGrid" AllowAlternatingRows="false" AllowFiltering="true" AllowPaging="true" PageSize="30" AllowSorting="true"
Data="@OFs" TItem="OF" ColumnWidth="200px" RowRender="@RowRender" CellRender="@CellRender" HeaderCellRender="@HeaderCellRender" GridLines="@gridLines"
FilterMode="FilterMode.CheckBoxList" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" Density="Density.Compact" id="controleOF">
</RadzenDataGrid>
I tried passing the styles into the print.js method but it doesn't work.
@code {
String styles = "<style>
body {
color: blue;
-webkit-print-color-adjust: exact;
}
table, th, td {
font-size:16px;
text-align: center;
color: red;
}
th {
background-color: #04AA6D;
color: white;
}
</style>";
private async Task PrintComponent(string elementId)
{
await JSRuntime.InvokeVoidAsync("printComponent", $"#{elementId}", styles);
}
}
Best regards
Gwendal


