Hi,
I have a Datagrid with some generated QR codes on it which I am printing out. However, one of the user requirements is to be able to print out to either A4, A5 or A6 size paper. Is there a SyncFusion to do this or do I need to resort to Javascript?
Also, as well as the contents of the DataGrid, I also need to include some HTML afterwards in the printout. Do I need to use Javascript again or could I print everything in one go using a Diagram rather than a DataGrid?
Thank you,
Maria
Hi, regarding the 2nd query - what I mean is to have an extra row at the bottom of my grid that contains entirely generated HTML. This would extend across all columns. Is that possible? If I have to resort to Javascript, please could you show me how as everything I have tried today has failed.
|
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Inputs
@inject IJSRuntime RunTime
<button @onclick="BtnClick">Print</button>
<SfGrid @ref="DataGrid" ID="Grid" DataSource="@Orders">
<GridEvents TValue="Order" DataBound="DataBoundHandler"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="140"></GridColumn>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
SfGrid<Order> DataGrid {get;set;}
private async Task BtnClick()
{
await RunTime.InvokeAsync<object>("gridfn");
await DataGrid.Print();
}
public async Task DataBoundHandler()
{
await RunTime.InvokeAsync<object>("RenderHTMLRow", "Grid");
}
} |
|
function RenderHTMLRow(gridId) {
var row = document.createElement('tr');
var cell = document.createElement('td');
cell.innerText = "new row";
row.appendChild(cell);
//append your customized HTML row here
var grid = document.getElementById(gridId);
grid.querySelector('.e-gridcontent').appendChild(row);
}
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 row = document.createElement('tr');
var cell = document.createElement('td');
cell.innerText = "new row";
row.appendChild(cell);
var table = e.querySelector(".e-gridcontent table");
//append the customized row to the grid based on your scenario
table.querySelector('tbody').appendChild(row)
printWind.resizeTo(screen.availWidth, screen.availHeight);
sf.base.print(e, printWind);
};
var old = sfBlazor.Grid.printGrid;
}
|
|
<head>
<script src="~/JavaScript.js"></script>
</head> |
Thank you, I will try this tomorrow and let you know how I get on.
Hi Jeevakanth, that did exactly as you said it would. instead of some text to be displayed, I need to display a HTML form so I changed it from cell.innerText to cell.innerHTML and it looks OK so far.
I need to do some more experimenting but thank you
Hi Jeevakanth, is it possible to pass in some additional parameters to the sfBlazor.Grid.printGrid Javascript function?