Is there a way to put a title/caption on the datagrid default printout?
Because right now it will just print the headers and rows only.
I can't find a way to put a title on the printout that I can customize to tell what data it is.
|
[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>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
. ..
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 title = document.createElement("div");
title.innerHTML = "Title: Print Grid";
title.style.fontSize = "40px";
title.style.height = "100px";
title.style.textAlign = "center";
addPrintEle = title.cloneNode(true);
e.insertBefore(addPrintEle, 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> |
Great, this works! I also added a reportTitle parameter on the javascript function so I could use it on different reports.
Hoping this would just be a grid property in the future :)
Hi Team,
https://www.syncfusion.com/forums/173642/blazor-datagrid-print-title-caption option not working in syncfusion version - 20.3.0.56.
Print title caption is working in syncfusion older vresion - 19.0, After, upgrading to the version 20.3.0.56 facing the issue.
sfBlazor.Grid.printGrid = function(e){ -> e is coming like below image in the upgraded version.
Hi Pravat,
We are currently Validating the reported query at our end and we will update the further details shortly. Until then we appreciate your patience.
Regards,
Naveen Palanivel
Hi Pravat,
Thanks for the Patient,
We would like to inform that , Print title 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 title above the Grid while performing print operation in latest version(20.3.0.60). 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 title = document.createElement("div"); title.innerHTML = "Title: Print Grid"; title.style.fontSize = "40px"; title.style.height = "100px"; title.style.textAlign = "center"; addPrintEle = title.cloneNode(true);
Grid.element.insertBefore(addPrintEle, 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