[Index.razor]
@inject IJSRuntime JsRuntime
@using Syncfusion.Blazor.Grids
<SfGrid @ref="DataGrid" DataSource="@Orders" ID="Grid" Toolbar="@ToolBarItems">
<GridEvents TValue="Order" OnToolbarClick="ToolbarClickHandler"></GridEvents>
<GridColumns>
. ..
</GridColumns>
</SfGrid>
@code{
private List<object> ToolBarItems = new List<object>() { "Print" };
. . .
private async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "Grid_print")
{
await JsRuntime.InvokeAsync<object>("gridfn");// This will override the default print function in the grid. Headers are customized here.
await DataGrid.Print();
}
}
. . .
} |
[interop.js]
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);
//create the elements
var img = document.createElement("img");
img.src = '. . .'; // refer the image in here
img.width = "500";
img.height = "500";
//append content for the elements
addPrintImg = img.cloneNode(true);
//append the created elements to the print window
e.insertBefore(addPrintImg, e.childNodes[0]);
printWind.resizeTo(screen.availWidth, screen.availHeight);
sf.base.print(e, printWind);
};
} |
[_Host.cshtml]
<head>
. ..
<link rel='nofollow' href="_content/Syncfusion.Blazor/styles/fabric.css" rel="stylesheet" />
<link rel='nofollow' href="css/site.css" rel="stylesheet" />
<script src="~/interop.js"></script>
</head> |
Hello,
This used to work correctly but after updating from 19.4.0.43 to version 20.3.0.60 it stopped working. Now it just opens a window. This is the code that used to work:
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 img = document.createElement("img");
img.src = 'images/picture.jpg';
img.width = "200";
img.height = "60";
var imgWrapperDiv = document.createElement("div");
imgWrapperDiv.className = "mb-3 mt-3 flex flex-row-reverse";
imgWrapperDiv.appendChild(img);
e.insertBefore(imgWrapperDiv, e.childNodes[0]);
printWind.resizeTo(screen.availWidth, screen.availHeight);
sf.base.print(e, printWind);
};
}
Hi Ivan,
We would like to inform that , Print logo caption is working in syncfusion older version(20.1.0.61). After volume 2 release(20.2.0.36) we made some behavior change. So it does not work. We made sample for the logo above the Grid while performing print operation in latest version(20.4.0.43). We also attached the snippet code and sample for your reference.
[interop.js]
window.gridfn = function () { sfBlazor.Grid.printGrid = function (e) { var Grid = sfBlazor.getCompInstance(e); var printWind = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no'); printWind.moveTo(0, 0); //create the elements var img = document.createElement("img"); img.src = 'back1.jpg'; img.width = "500"; img.height = "500"; //append content for the elements addPrintImg = img.cloneNode(true); //append the created elements to the print window Grid.element.insertBefore(addPrintImg, Grid.element.childNodes[0]) printWind.resizeTo(screen.availWidth, screen.availHeight); sf.base.print(Grid.element, printWind); }; } |
Please let us know if you have any concerns.
Regards,
Naveen Palanivel
Yes, this fixed the issue. Thank you!
Krasimir
Ivan, we are glad that the provided solution helped to solve the issue.