|
Host.cshtml
<head>
..
<script src="~/interop.js"></script>
..
</head> |
|
Interop.js
window.gridfn = function(){
sfBlazor.Grid.printGrid = function(e){
var printWind = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
..
..
sf.base.print(e, printWind);
};
} |
|
Index.razor
<button @onclick="BtnClick">Print</button>
<SfGrid @ref="DataGrid1" DataSource="@Orders" ID="Grid1">
..
<SfGrid>
<SfGrid DataSource="@Orders" ID="Grid2">
..
</SfGrid>
@code{
private async Task BtnClick()
{
await JsRuntime.InvokeAsync<object>("gridfn");// This will override the default print function in the grid. Headers are customized here.
await DataGrid1.Print();
}
}
|
|
window.gridfn = function(){
sfBlazor.Grid.printGrid = function(e){
var printWind = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
printWind.moveTo(0, 0);
var grid2 = document.getElementById('Grid2').cloneNode(true);
grid2.querySelector('.e-content').style.height='auto';
//If any element rendered in second grid is not needed while printing then it can be removed as toolbar removed like below code
var toolbar = grid2.querySelector('.e-toolbar');
if(toolbar) {
toolbar.remove();
}
e.appendChild(grid2);
printWind.resizeTo(screen.availWidth, screen.availHeight);
sf.base.print(e, printWind);
};
} |