diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/current-page/current-page.cs b/ej2-asp-core-mvc/code-snippet/grid/print/current-page/current-page.cs index 4019df2042..02cee14e8e 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/current-page/current-page.cs +++ b/ej2-asp-core-mvc/code-snippet/grid/print/current-page/current-page.cs @@ -1,5 +1,7 @@ public IActionResult Index() { - ViewBag.DataSource = OrderDetails.GetAllRecords(); + ViewBag.DataSource = OrdersDetails.GetAllRecords(); + ViewBag.dropdownData = new string[] { "AllPages", "CurrentPage" }; + return View(); } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/current-page/razor b/ej2-asp-core-mvc/code-snippet/grid/print/current-page/razor index 608ab99ccb..b1029cf6a4 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/current-page/razor +++ b/ej2-asp-core-mvc/code-snippet/grid/print/current-page/razor @@ -1,9 +1,22 @@ -@Html.EJS().Grid("Print").DataSource((IEnumerable)ViewBag.DataSource).Columns(col => +
+ + + @Html.EJS().DropDownList("dropdown").Index(0).DataSource(@ViewBag.dropdownData).Change("change").Render() + +
+ +@Html.EJS().Grid("Grid").DataSource((IEnumerable)ViewBag.DataSource).Columns(col => { col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); - col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add(); + col.Field("CustomerID").HeaderText("Customer ID").Width("150").Add(); col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add(); col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add(); -}).AllowPaging().Toolbar(new List() { "Print" }).PrintMode(Syncfusion.EJ2.Grids.PrintMode.CurrentPage).Render() \ No newline at end of file +}).AllowPaging().PageSettings(page => { page.PageSize(6); }).Toolbar(new List() { "Print" }).Render() + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/current-page/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/current-page/tagHelper index d3044d29ab..2199136bf4 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/current-page/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/grid/print/current-page/tagHelper @@ -1,8 +1,23 @@ - +
+ + + + +
+ + + - - + + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/external-btn.cs b/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/external-btn.cs index 4019df2042..47e5e3b61d 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/external-btn.cs +++ b/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/external-btn.cs @@ -1,5 +1,5 @@ public IActionResult Index() { - ViewBag.DataSource = OrderDetails.GetAllRecords(); + ViewBag.DataSource = OrdersDetails.GetAllRecords(); return View(); } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/razor b/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/razor index b7230490fd..b638a92107 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/razor +++ b/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/razor @@ -1,5 +1,6 @@ -@Html.EJS().Button("printbtn").Content("Print").IsPrimary(true).Render() - +
+ @Html.EJS().Button("printbtn").Content("Print").IsPrimary(true).Render() +
@Html.EJS().Grid("Print").DataSource((IEnumerable)ViewBag.DataSource).Columns(col => { col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/tagHelper index 5eacdac9cf..56842ed7a9 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/grid/print/external-btn/tagHelper @@ -1,10 +1,13 @@ - +
+ +
- - + + + diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/hierarchyprint.cs b/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/hierarchyprint.cs index f205693de8..f1bf5a0437 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/hierarchyprint.cs +++ b/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/hierarchyprint.cs @@ -3,5 +3,7 @@ public IActionResult Index() ViewBag.DataSource = OrdersDetails.GetAllRecords();; ViewBag.EmpDataSource = EmployeeView.GetAllRecords(); ViewBag.CustomerDataSource = Customer.GetAllRecords(); + ViewBag.dropdownData = new string[] { "Expanded", "All", "None" }; + return View(); } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/razor b/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/razor index 1d5072cb01..802089591f 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/razor +++ b/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/razor @@ -5,6 +5,7 @@ { new Syncfusion.EJ2.Grids.GridColumn(){ Field="CustomerID", HeaderText="Customer ID", Width="90", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Right }, new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipCountry", HeaderText="Ship Country", Width="90" }, + new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipAddress", HeaderText="ShipAddress", Width="90" }, } }; @@ -21,11 +22,23 @@ }; } -@Html.EJS().Grid("HierarchyPrint").DataSource((IEnumerable)ViewBag.EmpDataSource).HierarchyPrintMode(Syncfusion.EJ2.Grids.HierarchyGridPrintMode.All).Columns(col => -{ - col.Field("EmployeeID").HeaderText("Employee ID").Width("125").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); - col.Field("FirstName").HeaderText("Name").Width("125").Add(); - col.Field("Country").HeaderText("Country").Width("180").Add(); - col.Field("City").HeaderText("City").Width("135").Add(); +
+ + + @Html.EJS().DropDownList("dropdown").Index(0).DataSource(@ViewBag.dropdownData).Change("onModeChange").Render() + +
+ @Html.EJS().Grid("HierarchyPrint").DataSource((IEnumerable)ViewBag.EmpDataSource).Columns(col => + { + col.Field("EmployeeID").HeaderText("Employee ID").Width("125").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("FirstName").HeaderText("Name").Width("125").Add(); + col.Field("Country").HeaderText("Country").Width("180").Add(); + col.Field("City").HeaderText("City").Width("135").Add(); -}).AllowSorting().Toolbar(new List() { "Print"}).ChildGrid(ChildGrid).Render() + }).Toolbar(new List() { "Print" }).ChildGrid(ChildGrid).Render() + diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/tagHelper index 50a70db576..003d4c9362 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/grid/print/hierarchyprint/tagHelper @@ -1,35 +1,51 @@ - @{ - var SecondChildGrid = new Syncfusion.EJ2.Grids.Grid() - { - DataSource = (IEnumerable)ViewBag.CustomerDataSource, - QueryString = "CustomerID", - Columns = new List { + +@{ + var SecondChildGrid = new Syncfusion.EJ2.Grids.Grid() + { + DataSource = (IEnumerable)ViewBag.CustomerDataSource, + QueryString = "CustomerID", + Columns = new List { new Syncfusion.EJ2.Grids.GridColumn(){ Field="CustomerID", HeaderText="Customer ID", Width="90", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Right }, new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipCountry", HeaderText="Country", Width="90" }, - } - }; - } + new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipAddress", HeaderText="Ship Address", Width="90" }, + + } + }; +} - @{ - var ChildGrid = new Syncfusion.EJ2.Grids.Grid() { - DataSource = (IEnumerable)ViewBag.DataSource, - QueryString = "EmployeeID", - Columns = new List { +@{ + var ChildGrid = new Syncfusion.EJ2.Grids.Grid() + { + DataSource = (IEnumerable)ViewBag.DataSource, + QueryString = "EmployeeID", + Columns = new List { new Syncfusion.EJ2.Grids.GridColumn(){ Field="OrderID", HeaderText="Order ID", Width="120" }, new Syncfusion.EJ2.Grids.GridColumn(){ Field="Freight", HeaderText="Freight", Width="120", Format="C2", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Right }, new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipName", HeaderText="Ship Name", Width="150" }, new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipCity", HeaderText="Ship City", Width="120" }, - }, - ChildGrid = SecondChildGrid - }; - } + }, + ChildGrid = SecondChildGrid + }; +} - +
+ + + + +
+ - + + diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs b/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs index f650c2d757..35e0c7fa1c 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs +++ b/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs @@ -1,5 +1,6 @@ public IActionResult Index() { - ViewBag.dataSource = OrderDetails.GetAllRecords(); + ViewBag.DataSource = OrdersDetails.GetAllRecords(); + ViewBag.EmployeeData =Employees.GetAllRecords(); return View(); } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/razor b/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/razor index 50964a633d..3846fca91b 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/razor +++ b/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/razor @@ -1,36 +1,42 @@
Master Grid - @Html.EJS().Grid("masterGrid").DataSource((IEnumerable)ViewBag.dataSource).Width("auto").SelectedRowIndex(0).Columns(col => - { - col.Field("EmployeeID").HeaderText("EmployeeID").IsPrimaryKey(true).Add(); - col.Field("OrderID").HeaderText("OrderID").Add(); - col.Field("CustomerID").HeaderText("FirstName").Add(); - }).RowSelected("selected").BeforePrint("beforePrint").Toolbar(new List() { "Print" }).Render() + @Html.EJS().Grid("masterGrid").DataSource((IEnumerable)ViewBag.EmployeeData).SelectedRowIndex(1).Columns(col => +{ + col.Field("ContactName").HeaderText("Customer Name").Width(150).Add(); + col.Field("CompanyName").HeaderText("CompanyName").Width(150).Add(); + col.Field("Address").HeaderText("Address").Width(150).Add(); + col.Field("Country").HeaderText("Country").Width(130).Add(); + +}).RowSelected("rowSelected").BeforePrint("beforePrint").Toolbar(new List() { "Print" }).Render() -

Showing orders of Customer:

+

Showing orders of Customer:

- @Html.EJS().Grid("detailGrid").DataSource((IEnumerable)ViewBag.dataSource1).Columns(col => - { - col.Field("EmployeeID").HeaderText("EmployeeID").IsPrimaryKey(true).Add(); - col.Field("ShipCountry").HeaderText("ShipCountry").Add(); - col.Field("ShipName").HeaderText("ShipName").Add(); - }).Render() +@Html.EJS().Grid("childGrid").Columns(col => +{ + col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("ShipName").HeaderText("Ship Name").Width("120").Add(); + col.Field("ShipAddress").HeaderText("Ship Address").Width("150").Add(); + col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add(); + + +}).Render() \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/tagHelper index 6b00303b69..4a36a45612 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/grid/print/masterdetailgrid/tagHelper @@ -1,40 +1,43 @@ @using System.Text.Json;
- + - - - + + + +
-

Showing orders of Customer:

-
- - - - - - - -
+

Showing orders of Customer:

+ + + + + + + + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/print.cs b/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/print.cs new file mode 100644 index 0000000000..47e5e3b61d --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/print.cs @@ -0,0 +1,5 @@ +public IActionResult Index() +{ + ViewBag.DataSource = OrdersDetails.GetAllRecords(); + return View(); +} \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/razor b/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/razor new file mode 100644 index 0000000000..958b1ad0b7 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/razor @@ -0,0 +1,42 @@ +
+ @Html.EJS().Button("print").CssClass("e-danger").Content("Print").Render() +
+@Html.EJS().Grid("HierarchyPrint").DataSource((IEnumerable)ViewBag.DataSource).Columns(col => +{ + col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add(); + col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + +}).AllowPaging().PageSettings(page => { page.PageSize(10); }).PrintMode(Syncfusion.EJ2.Grids.PrintMode.CurrentPage).ActionComplete("actionComplete").DataBound("dataBound").BeforePrint("beforePrint").Render() + +@Html.EJS().Chart("chart").Series(series => +{ + series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).Width(1).XName("OrderDate") + .YName("Freight").ColumnWidth(0.4).Marker(mr => mr.Visible(true)).Add(); + +}).PrimaryXAxis(px =>px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime) +.LabelFormat("MMMd")).PrimaryYAxis(py =>py.LabelFormat("{value}")).Title("Order Data").Render() + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/tagHelper new file mode 100644 index 0000000000..b91d952122 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-custom/tagHelper @@ -0,0 +1,55 @@ +
+ +
+ + + + + + + + + + +

Chart

+
+ + + + + + + + + +
+ + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-select/print.cs b/ej2-asp-core-mvc/code-snippet/grid/print/print-select/print.cs new file mode 100644 index 0000000000..47e5e3b61d --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-select/print.cs @@ -0,0 +1,5 @@ +public IActionResult Index() +{ + ViewBag.DataSource = OrdersDetails.GetAllRecords(); + return View(); +} \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-select/razor b/ej2-asp-core-mvc/code-snippet/grid/print/print-select/razor new file mode 100644 index 0000000000..f7a7496d08 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-select/razor @@ -0,0 +1,22 @@ +@Html.EJS().Grid("Grid").DataSource((IEnumerable)ViewBag.DataSource).BeforePrint("beforePrint").Columns(col => +{ + col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("CustomerID").HeaderText("Customer ID").Width("150").Add(); + col.Field("ShipCity").HeaderText("Ship City").Width("150").Add(); + col.Field("ShipName").HeaderText("Ship Name").Width("150").Add(); + +}).AllowPaging().SelectionSettings(select => select.Type(Syncfusion.EJ2.Grids.SelectionType.Multiple)).PageSettings(page => page.PageSize(6)).Toolbar(new List() { "Print" }).Render() + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-select/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/print-select/tagHelper new file mode 100644 index 0000000000..12f97906c9 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-select/tagHelper @@ -0,0 +1,25 @@ + + + + + + + + + + + diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-style/print.cs b/ej2-asp-core-mvc/code-snippet/grid/print/print-style/print.cs new file mode 100644 index 0000000000..47e5e3b61d --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-style/print.cs @@ -0,0 +1,5 @@ +public IActionResult Index() +{ + ViewBag.DataSource = OrdersDetails.GetAllRecords(); + return View(); +} \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-style/razor b/ej2-asp-core-mvc/code-snippet/grid/print/print-style/razor new file mode 100644 index 0000000000..196351c334 --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-style/razor @@ -0,0 +1,37 @@ +@Html.EJS().Grid("Grid").DataSource((IEnumerable)ViewBag.DataSource).BeforePrint("beforePrint").Columns(col => +{ + col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("CustomerID").HeaderText("Customer ID").Width("150").Add(); + col.Field("ShipCity").HeaderText("Ship City").Width("150").Add(); + col.Field("ShipName").HeaderText("Ship Name").Width("150").Add(); + +}).Toolbar(new List() { "Print" }).Render() + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print-style/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/print-style/tagHelper new file mode 100644 index 0000000000..06179efa8a --- /dev/null +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print-style/tagHelper @@ -0,0 +1,36 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print/print.cs b/ej2-asp-core-mvc/code-snippet/grid/print/print/print.cs index 4019df2042..47e5e3b61d 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/print/print.cs +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print/print.cs @@ -1,5 +1,5 @@ public IActionResult Index() { - ViewBag.DataSource = OrderDetails.GetAllRecords(); + ViewBag.DataSource = OrdersDetails.GetAllRecords(); return View(); } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print/razor b/ej2-asp-core-mvc/code-snippet/grid/print/print/razor index 4cb27541ab..1e350d417c 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/print/razor +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print/razor @@ -3,7 +3,7 @@ col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add(); col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add(); - col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("Freight").HeaderText("Freight").Width("130").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add(); }).AllowPaging().Toolbar(new List() { "Print" }).Render() \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/print/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/print/tagHelper index 7432d706db..185529820c 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/print/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/grid/print/print/tagHelper @@ -1,8 +1,9 @@ - + - - + + + \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/razor b/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/razor index b381685cd3..2e5368d1f9 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/razor +++ b/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/razor @@ -1,33 +1,31 @@ -@Html.EJS().Grid("Print").DataSource((IEnumerable)ViewBag.DataSource).ToolbarClick("toolbarClick").PrintComplete("printComplete").Columns(col => +@Html.EJS().Grid("Grid").DataSource((IEnumerable)ViewBag.DataSource).ToolbarClick("toolbarClick").PrintComplete("printComplete").Columns(col => { col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); - col.Field("CustomerID").HeaderText("Customer Name").Visible(false).Width("150").Add(); - col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add(); - col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); + col.Field("CustomerID").HeaderText("Customer ID").Visible(false).Width("150").Add(); col.Field("ShipCity").HeaderText("Ship City").Width("150").Add(); + col.Field("ShipName").HeaderText("Ship Name").Width("150").Add(); -}).AllowPaging().Toolbar(new List() { "Print" }).Render() +}).Toolbar(new List() { "Print" }).Render() \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/show-hide.cs b/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/show-hide.cs index 4019df2042..48ab9c49b6 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/show-hide.cs +++ b/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/show-hide.cs @@ -1,5 +1,5 @@ public IActionResult Index() { - ViewBag.DataSource = OrderDetails.GetAllRecords(); - return View(); + ViewBag.DataSource = OrdersDetails.GetAllRecords(); + return View(); } \ No newline at end of file diff --git a/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/tagHelper b/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/tagHelper index f1392949a0..088972d0fe 100644 --- a/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/tagHelper +++ b/ej2-asp-core-mvc/code-snippet/grid/print/show-hide-columns/tagHelper @@ -1,4 +1,4 @@ - + @@ -6,27 +6,25 @@ - \ No newline at end of file diff --git a/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/print.md b/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/print.md index 88e4803e8c..f146e2c82b 100644 --- a/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/print.md +++ b/ej2-asp-core-mvc/grid/EJ2_ASP.MVC/print.md @@ -8,227 +8,182 @@ publishingplatform: ##Platform_Name## documentation: ug --- +# Print in ASP.NET MVC Grid component -# Print in ASP.NET MVC Grid Component +The printing feature in Syncfusion Grid allows you to easily generate and print a representation of the grid's content for better offline accessibility and documentation. You can enable this feature using either the grid's toolbar or the programmatically available `print` method. -To print the Grid, use the [`print`](https://ej2.syncfusion.com/documentation/api/grid/#print) method from grid instance. The print option can be displayed on the [`Toolbar`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_Toolbar) by adding the **Print** toolbar item. - -{% if page.publishingplatform == "aspnet-core" %} +To add the printing option to the grid's toolbar, simply include the [Toolbar](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_Toolbar) property in your grid configuration and add the **Print** as toolbar item. This will allow you to directly initiate the printing process while click on the Print item from the toolbar. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} -{% include code-snippet/grid/print/print/tagHelper %} -{% endhighlight %} -{% highlight c# tabtitle="Print.cs" %} -{% include code-snippet/grid/print/print/print.cs %} -{% endhighlight %} -{% endtabs %} - -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} {% include code-snippet/grid/print/print/razor %} {% endhighlight %} -{% highlight c# tabtitle="Print.cs" %} +{% highlight c# tabtitle="print.cs" %} {% include code-snippet/grid/print/print/print.cs %} {% endhighlight %} {% endtabs %} -{% endif %} - +![Print](../images/print/print.png) ## Page setup -Some of the print options cannot be configured through JavaScript code. So, you have to customize the layout, paper size, and margin options using the browser page setup dialog. Refer to the following links to know more about the browser page setup: - -* [`Chrome`](https://support.google.com/chrome/answer/1069693?hl=en&visit_id=1-636335333734668335-3165046395&rd=1) -* [`Firefox`](https://support.mozilla.org/en-US/kb/how-print-web-pages-firefox) -* [`Safari`](http://www.mintprintables.com/print-tips/adjust-margins-osx/) -* [`IE`](http://www.helpteaching.com/help/print/index.htm) +When printing a webpage, some print options, such as layout, paper size, and margin settings, cannot be configured through JavaScript code. Instead, you need to customize these settings using the browser's page setup dialog. Below are links to the page setup guides for popular web browsers: -## Print using an external button +* [Chrome](https://support.google.com/chrome/answer/1069693?hl=en&visit_id=1-636335333734668335-3165046395&rd=1) +* [Firefox](https://support.mozilla.org/en-US/kb/how-print-web-pages-firefox) +* [Safari](http://www.mintprintables.com/print-tips/adjust-margins-osx/) +* [IE](http://www.helpteaching.com/help/print/index.htm) -To print the grid from an external button, invoke the [`print`](https://ej2.syncfusion.com/documentation/api/grid/#print) method. +## Print by external button -{% if page.publishingplatform == "aspnet-core" %} +You can print the grid's content using an external button by utilizing the `print` method. This method allows you to trigger the printing process programmatically. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} -{% include code-snippet/grid/print/external-btn/tagHelper %} -{% endhighlight %} -{% highlight c# tabtitle="External-btn.cs" %} -{% include code-snippet/grid/print/external-btn/external-btn.cs %} -{% endhighlight %} -{% endtabs %} - -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} {% include code-snippet/grid/print/external-btn/razor %} {% endhighlight %} {% highlight c# tabtitle="External-btn.cs" %} {% include code-snippet/grid/print/external-btn/external-btn.cs %} {% endhighlight %} {% endtabs %} -{% endif %} - - -## Print the visible page +![Print by external button](../images/print/print-external.png) -By default, the grid prints all the pages. To print the current page alone, set the [`PrintMode`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_PrintMode) to **CurrentPage**. +## Print visible Page -{% if page.publishingplatform == "aspnet-core" %} +By default, the Syncfusion ASP.NET MVC Grid prints all the pages of the grid. The [PrintMode](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_PrintMode) property within the grid grants you control over the printing process. However, if you want to print only the current visible page, you can achieve this by setting the `PrintMode` property to **CurrentPage**. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} -{% include code-snippet/grid/print/current-page/tagHelper %} +{% include code-snippet/grid/print/current-page/razor %} {% endhighlight %} {% highlight c# tabtitle="Current-page.cs" %} {% include code-snippet/grid/print/current-page/current-page.cs %} {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} +![Print visible Page](../images/print/print-current.png) + +## Print only selected records + +By default, the Syncfusion ASP.NET MVC Grid prints all the data bound to its dataSource. However, there might be cases where you want to print only the selected records from the grid. The ASP.NET MVC Grid provides an option to achieve this by binding to the [BeforePrint](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event, where you can replace the rows of the printing grid with the selected rows. + +Below is an example code that demonstrates how to print only the selected records from the ASP.NET MVC Grid: {% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/current-page/razor %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/grid/print/print-select/razor %} {% endhighlight %} -{% highlight c# tabtitle="Current-page.cs" %} -{% include code-snippet/grid/print/current-page/current-page.cs %} +{% highlight c# tabtitle="Print.cs" %} +{% include code-snippet/grid/print/print-select/print.cs %} {% endhighlight %} {% endtabs %} -{% endif %} - +![Print only selected records](../images/print/print-select.png) ## Print the hierarchy grid -By default, the grid will be print the master and expanded child grids alone. you can change the print option by using the [`hierarchyPrintMode`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_HierarchyPrintMode) property. The available options are, +The Syncfusion ASP.NET MVC Grid allows you to print hierarchy grids, which consist of a parent grid and its child grids. By default, when you print a hierarchy grid, it includes the parent grid and expanded child grids only. However, you can customize the print behavior using the [HierarchyPrintMode](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_HierarchyPrintMode) property. -| Mode | Behavior | -|----------|-------------| -| Expanded | Prints the master grid with expanded child grids. | -| All | Prints the master grid with all the child grids. | -| None | Prints the master grid alone. | +The `HierarchyPrintMode` property in the ASP.NET MVC Grid lets you control the printing behavior for hierarchy grids. You can choose from three options: -{% if page.publishingplatform == "aspnet-core" %} +| Mode | Behavior | +| -------- | ------------------------------------------------------------------------------- | +| Expanded | Prints the parent grid with expanded child grids. | +| All | Prints the parent grid with all the child grids, whether expanded or collapsed. | +| None | Prints the parent grid alone. | {% tabs %} -{% highlight c# tabtitle="CSHTML" %} -{% include code-snippet/grid/print/hierarchyprint/tagHelper %} -{% endhighlight %} -{% highlight c# tabtitle="Hierarchyprint.cs" %} -{% include code-snippet/grid/print/hierarchyprint/hierarchyprint.cs %} -{% endhighlight %} -{% highlight c# tabtitle="Hierarchyprint.cs" %} -{% include code-snippet/grid/print/hierarchyprint/hierarchyprint.cs %} -{% endhighlight %} -{% endtabs %} - -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} +{% highlight cshtml tabtitle="CSHTML" %} {% include code-snippet/grid/print/hierarchyprint/razor %} {% endhighlight %} {% highlight c# tabtitle="Hierarchyprint.cs" %} {% include code-snippet/grid/print/hierarchyprint/hierarchyprint.cs %} {% endhighlight %} -{% highlight c# tabtitle="Hierarchyprint.cs" %} -{% include code-snippet/grid/print/hierarchyprint/hierarchyprint.cs %} -{% endhighlight %} {% endtabs %} -{% endif %} - - -N> By default, the hierarchy grid prints the expanded child grids from the visible page only. Refer [To Print the expanded state grid from all pages](./how-to/#print-the-expanded-state-from-other-pages). +![Print the hierarchy grid](../images/print/print-hierachy.png) ## Print the master detail grid -The Grid has the option to visualize details of a record in another Grid in a master and detailed manner. By default, Grid will print the master grid alone. Instead of this, it is possible to print both the master and detail grids by using the [BeforePrint](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event of the Grid. - -In the following sample, the detail grid is added to the `element` argument of the `BeforePrint` event, resulting in both the master and detail grids being printed on the page. +The Syncfusion ASP.NET MVC Grid provides the option to visualize details of a record in another grid in a master-detail manner. By default, when you print a master-detail grid, only the master grid is included in the print output. However, you can customize the print behavior to include both the master and detail grids using the `BeforePrint` event of the grid. -{% if page.publishingplatform == "aspnet-core" %} +The [BeforePrint](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint)event in the ASP.NET MVC Grid is triggered before the actual printing process begins. You can handle this event to customize the print output. By adding the detail grid to the `element` argument of the `BeforePrint` event, you can ensure that both the master and detail grids are printed on the page. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} -{% include code-snippet/grid/print/masterdetailgrid/tagHelper %} -{% endhighlight %} -{% highlight c# tabtitle="Master-Detail.cs" %} -{% include code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs %} -{% endhighlight %} -{% endtabs %} - -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} {% include code-snippet/grid/print/masterdetailgrid/razor %} {% endhighlight %} {% highlight c# tabtitle="Master-Detail.cs" %} {% include code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs %} {% endhighlight %} {% endtabs %} -{% endif %} +![Print the master detail grid](../images/print/print-master.png) ## Print large number of columns -By default, the browser uses A4 as page size option to print pages and to adapt the size of the page the browser print preview will auto-hide the overflowed contents. Hence grid with large number of columns will cut off to adapt the print page. - -To show large number of columns when printing, adjust the scale option from print option panel based on your content size. +When printing a grid with a large number of columns, the browser's default page size (usually A4) might not be sufficient to display all the columns properly. As a result, the browser's print preview may automatically hide the overflowed content, leading to a cut-off appearance. -![Scale Option Setting](./images/print-preview.png) +To show a large number of columns when printing, you can adjust the scale option from the print option panel based on your content size. This will allow you to fit the entire grid content within the printable area. -## Show or Hide columns while Printing +![Scale Option Setting](../images/print-preview.png) -You can show a hidden column or hide a visible column while printing the grid using [`ToolbarClick`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) and [`PrintComplete`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_PrintComplete) events. +## Show or hide columns while printing -In the [`ToolbarClick`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) event, based on **args.item.id** as **grid_print**. We can show or hide columns by setting [`Visible`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.GridColumn.html#Syncfusion_EJ2_Grids_GridColumn_Visible) property of [`Column`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.GridColumn.html) to **true** or **false** respectively. +In the Syncfusion ASP.NET MVC Grid, you have the flexibility to control the visibility of columns during the printing process. You can dynamically show or hide specific columns using the [ToolbarClick](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) and [PrintComplete](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_PrintComplete) events while printing. This capability enhances your control over which columns are included in the printed output, allowing you to tailor the printed grid to your specific needs. -In the [`PrintComplete`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_PrintComplete) event, We have reversed the state back to the previous state. +In the `ToolbarClick` event, you can show or hide columns by setting `Column.Visible` property to **true** or **false** respectively. -In the below example, we have **CustomerID** as a hidden column in the grid. While printing, we have changed **CustomerID** to visible column and **ShipCity** as hidden column. +In the `PrintComplete` event, the column visibility state is reset back to its original configuration. -{% if page.publishingplatform == "aspnet-core" %} +Here's a code example that demonstrates how to show a hidden column (CustomerID) and hide a visible column (ShipCity) during printing and then reset their visibility after printing: {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} -{% include code-snippet/grid/print/show-hide-columns/tagHelper %} +{% include code-snippet/grid/print/show-hide-columns/razor %} {% endhighlight %} {% highlight c# tabtitle="Show-hide.cs" %} {% include code-snippet/grid/print/show-hide-columns/show-hide.cs %} {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} +![Show or hide columns while printing](../images/print/print-hide.png) + +## Limitations of printing large data + +Printing a large volume of data all at once in the grid can have certain limitations due to potential browser performance issues. Rendering numerous DOM elements on a single page can lead to browser slowdowns or even hang the browser. The grid offers a solution to manage extensive datasets through virtualization. However, it's important to note that virtualization for both rows and columns is not feasible during the printing process. + +If printing all the data remains a requirement, an alternative approach is recommended. Exporting the grid data to formats like [Excel](https://ej2.syncfusion.com/aspnetcore/documentation/grid/excel-export/excel-exporting) or [CSV](https://ej2.syncfusion.com/aspnetcore/documentation/grid/excel-export/excel-exporting) or [Pdf](https://ej2.syncfusion.com/aspnetcore/documentation/grid/pdf-export/pdf-export) is advised. This exported data can then be printed using non-web-based applications, mitigating the potential performance challenges associated with printing large datasets directly from the browser. + +## Retain grid styles while printing + +The Syncfusion ASP.NET MVC Grid provides a [BeforePrint](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event that allows you to customize the appearance and styles of the grid before it is sent to the printer. By handling this event, you can ensure that the grid retains its styles and appearance while printing. {% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/show-hide-columns/razor %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/grid/print/print-style/razor %} {% endhighlight %} -{% highlight c# tabtitle="Show-hide.cs" %} -{% include code-snippet/grid/print/show-hide-columns/show-hide.cs %} +{% highlight c# tabtitle="print.cs" %} +{% include code-snippet/grid/print/print-style/print.cs %} {% endhighlight %} {% endtabs %} -{% endif %} +![Retain grid styles while printing](../images/print/print-style.png) +## Print grid along with other components -## Limitations of Printing Large Data +To print the Syncfusion ASP.NET MVC Grid along with another component, such as a chart, you can use the [BeforePrint](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event of the grid. In this event, you can clone the content of the other component and append it to the print document. -When grid contains large number of data, printing all the data at once is not a best option for the browser performance. Because to render all the DOM elements in one page will produce performance issues in the browser. It leads to browser slow down or browser hang. Grid have option to handle large number of data by Virtualization. However while printing, it is not possible to use virtualization for rows and columns. +Here is an example of how to print grid along with chart component: -If printing of all the data is still needed, we suggest to Export the grid to **Excel** or **CSV** or **Pdf** and then print it from another non-web based application. - -## See Also +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/grid/print/print-custom/razor %} +{% endhighlight %} +{% highlight c# tabtitle="print.cs" %} +{% include code-snippet/grid/print/print-custom/print.cs %} +{% endhighlight %} +{% endtabs %} -* [How to Print the expanded state grid from all pages](./how-to/print-the-expanded-state-from-other-pages) -* [How to print the Grid using external button in ASP.NET MVC Grid](https://www.syncfusion.com/forums/136763/how-to-print-the-grid-using-external-button-in-asp-net-mvc-grid) -* [How to print the custom report in ASP.NET MVC Grid](https://www.syncfusion.com/forums/141249/how-to-print-the-custom-report-in-asp-net-mvc-grid) \ No newline at end of file +![Print grid along with other components](../images/print/print-custom.png) \ No newline at end of file diff --git a/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/print.md b/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/print.md index 7131e9627f..a273ce4b1e 100644 --- a/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/print.md +++ b/ej2-asp-core-mvc/grid/EJ2_ASP.NETCORE/print.md @@ -8,50 +8,35 @@ publishingplatform: ##Platform_Name## documentation: ug --- +# Print in ASP.NET Core Grid component -# Print in ASP.NET Core Grid Component +The printing feature in Syncfusion Grid allows you to easily generate and print a representation of the grid's content for better offline accessibility and documentation. You can enable this feature using either the grid's toolbar or the programmatically available `print` method. -To print the Grid, use the **print** method from grid instance. The print option can be displayed on the [`toolbar`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_Toolbar) by adding the **Print** toolbar item. - -{% if page.publishingplatform == "aspnet-core" %} +To add the printing option to the grid's toolbar, simply include the [toolbar](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_Toolbar) property in your grid configuration and add the **Print** as toolbar item. This will allow you to directly initiate the printing process while click on the Print item from the toolbar. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} {% include code-snippet/grid/print/print/tagHelper %} {% endhighlight %} -{% highlight c# tabtitle="Print.cs" %} -{% include code-snippet/grid/print/print/print.cs %} -{% endhighlight %} -{% endtabs %} - -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/print/razor %} -{% endhighlight %} -{% highlight c# tabtitle="Print.cs" %} +{% highlight c# tabtitle="print.cs" %} {% include code-snippet/grid/print/print/print.cs %} {% endhighlight %} {% endtabs %} -{% endif %} - +![Print](../images/print/print.png) ## Page setup -Some of the print options cannot be configured through JavaScript code. So, you have to customize the layout, paper size, and margin options using the browser page setup dialog. Refer to the following links to know more about the browser page setup: - -* [`Chrome`](https://support.google.com/chrome/answer/1069693?hl=en&visit_id=1-636335333734668335-3165046395&rd=1) -* [`Firefox`](https://support.mozilla.org/en-US/kb/how-print-web-pages-firefox) -* [`Safari`](http://www.mintprintables.com/print-tips/adjust-margins-osx/) -* [`IE`](http://www.helpteaching.com/help/print/index.htm) +When printing a webpage, some print options, such as layout, paper size, and margin settings, cannot be configured through JavaScript code. Instead, you need to customize these settings using the browser's page setup dialog. Below are links to the page setup guides for popular web browsers: -## Print using an external button +* [Chrome](https://support.google.com/chrome/answer/1069693?hl=en&visit_id=1-636335333734668335-3165046395&rd=1) +* [Firefox](https://support.mozilla.org/en-US/kb/how-print-web-pages-firefox) +* [Safari](http://www.mintprintables.com/print-tips/adjust-margins-osx/) +* [IE](http://www.helpteaching.com/help/print/index.htm) -To print the grid from an external button, invoke the **print** method. +## Print by external button -{% if page.publishingplatform == "aspnet-core" %} +You can print the grid's content using an external button by utilizing the `print` method. This method allows you to trigger the printing process programmatically. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} @@ -62,25 +47,11 @@ To print the grid from an external button, invoke the **print** method. {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/external-btn/razor %} -{% endhighlight %} -{% highlight c# tabtitle="External-btn.cs" %} -{% include code-snippet/grid/print/external-btn/external-btn.cs %} -{% endhighlight %} -{% endtabs %} -{% endif %} - +![Print by external button](../images/print/print-external.png) +## Print visible Page -## Print the visible page - -By default, the grid prints all the pages. To print the current page alone, set the [`PrintMode`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_PrintMode) to **CurrentPage**. - -{% if page.publishingplatform == "aspnet-core" %} +By default, the Syncfusion ASP.NET Core Grid prints all the pages of the grid. The [printMode](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_PrintMode) property within the grid grants you control over the printing process. However, if you want to print only the current visible page, you can achieve this by setting the `printMode` property to **CurrentPage**. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} @@ -91,31 +62,36 @@ By default, the grid prints all the pages. To print the current page alone, set {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} +![Print visible Page](../images/print/print-current.png) + +## Print only selected records + +By default, the Syncfusion ASP.NET Core Grid prints all the data bound to its dataSource. However, there might be cases where you want to print only the selected records from the grid. The ASP.NET Core Grid provides an option to achieve this by binding to the [beforePrint](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event, where you can replace the rows of the printing grid with the selected rows. + +Below is an example code that demonstrates how to print only the selected records from the ASP.NET Core Grid: {% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/current-page/razor %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/grid/print/print-select/tagHelper %} {% endhighlight %} -{% highlight c# tabtitle="Current-page.cs" %} -{% include code-snippet/grid/print/current-page/current-page.cs %} +{% highlight c# tabtitle="Print.cs" %} +{% include code-snippet/grid/print/print-select/print.cs %} {% endhighlight %} {% endtabs %} -{% endif %} - +![Print only selected records](../images/print/print-select.png) ## Print the hierarchy grid -By default, the grid will be print the master and expanded child grids alone. you can change the print option by using the [`hierarchyPrintMode`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_HierarchyPrintMode) property. The available options are, +The Syncfusion ASP.NET Core Grid allows you to print hierarchy grids, which consist of a parent grid and its child grids. By default, when you print a hierarchy grid, it includes the parent grid and expanded child grids only. However, you can customize the print behavior using the [hierarchyPrintMode](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_HierarchyPrintMode) property. -| Mode | Behavior | -|----------|-------------| -| Expanded | Prints the master grid with expanded child grids. | -| All | Prints the master grid with all the child grids. | -| None | Prints the master grid alone. | +The `hierarchyPrintMode` property in the ASP.NET Core Grid lets you control the printing behavior for hierarchy grids. You can choose from three options: -{% if page.publishingplatform == "aspnet-core" %} +| Mode | Behavior | +| -------- | ------------------------------------------------------------------------------- | +| Expanded | Prints the parent grid with expanded child grids. | +| All | Prints the parent grid with all the child grids, whether expanded or collapsed. | +| None | Prints the parent grid alone. | {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} @@ -126,29 +102,13 @@ By default, the grid will be print the master and expanded child grids alone. yo {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/hierarchyprint/razor %} -{% endhighlight %} -{% highlight c# tabtitle="Hierarchyprint.cs" %} -{% include code-snippet/grid/print/hierarchyprint/hierarchyprint.cs %} -{% endhighlight %} -{% endtabs %} -{% endif %} - - - -N> By default, the hierarchy grid prints the expanded child grids from the visible page only. Refer [To Print the expanded state grid from all pages](./how-to/print-the-expanded-state-from-other-pages) +![Print the hierarchy grid](../images/print/print-hierachy.png) ## Print the master detail grid -The Grid has the option to visualize details of a record in another Grid in a master and detailed manner. By default, Grid will print the master grid alone. Instead of this, it is possible to print both the master and detail grids by using the [beforePrint](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event of the Grid. +The Syncfusion ASP.NET Core Grid provides the option to visualize details of a record in another grid in a master-detail manner. By default, when you print a master-detail grid, only the master grid is included in the print output. However, you can customize the print behavior to include both the master and detail grids using the `beforePrint` event of the grid. -In the following sample, the detail grid is added to the `element` argument of the `beforePrint` event, resulting in both the master and detail grids being printed on the page. - -{% if page.publishingplatform == "aspnet-core" %} +The [beforePrint](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event in the ASP.NET Core Grid is triggered before the actual printing process begins. You can handle this event to customize the print output. By adding the detail grid to the `element` argument of the `beforePrint` event, you can ensure that both the master and detail grids are printed on the page. {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} @@ -159,37 +119,25 @@ In the following sample, the detail grid is added to the `element` argument of t {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} - -{% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/masterdetailgrid/razor %} -{% endhighlight %} -{% highlight c# tabtitle="Master-Detail.cs" %} -{% include code-snippet/grid/print/masterdetailgrid/masterdetailgrid.cs %} -{% endhighlight %} -{% endtabs %} -{% endif %} +![Print the master detail grid](../images/print/print-master.png) ## Print large number of columns -By default, the browser uses A4 as page size option to print pages and to adapt the size of the page the browser print preview will auto-hide the overflowed contents. Hence grid with large number of columns will cut off to adapt the print page. +When printing a grid with a large number of columns, the browser's default page size (usually A4) might not be sufficient to display all the columns properly. As a result, the browser's print preview may automatically hide the overflowed content, leading to a cut-off appearance. -To show large number of columns when printing, adjust the scale option from print option panel based on your content size. +To show a large number of columns when printing, you can adjust the scale option from the print option panel based on your content size. This will allow you to fit the entire grid content within the printable area. -![Scale Option Setting](./images/print-preview.png) +![Scale Option Setting](../images/print-preview.png) -## Show or Hide columns while Printing +## Show or hide columns while printing -You can show a hidden column or hide a visible column while printing the grid using [`toolbarClick`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) and [`printComplete`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_PrintComplete) events. +In the Syncfusion ASP.NET Core Grid, you have the flexibility to control the visibility of columns during the printing process. You can dynamically show or hide specific columns using the [toolbarClick](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) and [printComplete](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_PrintComplete) events while printing. This capability enhances your control over which columns are included in the printed output, allowing you to tailor the printed grid to your specific needs. -In [`toolbarClick`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_ToolbarClick) event, based on **args.item.id** as **grid_print**. We can show or hide columns by setting [`visible`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.GridColumn.html#Syncfusion_EJ2_Grids_GridColumn_Visible) property of **e-grid-column** to **true** or **false** respectively. +In the `toolbarClick` event, you can show or hide columns by setting `column.visible` property to **true** or **false** respectively. -In [`printComplete`](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Grids.Grid.html#Syncfusion_EJ2_Grids_Grid_PrintComplete) event, We have reversed the state back to the previous state. +In the `printComplete` event, the column visibility state is reset back to its original configuration. -In the below example, we have **CustomerID** as a hidden column in the grid. While printing, we have changed **CustomerID** to visible column and **ShipCity** as hidden column. - -{% if page.publishingplatform == "aspnet-core" %} +Here's a code example that demonstrates how to show a hidden column (CustomerID) and hide a visible column (ShipCity) during printing and then reset their visibility after printing: {% tabs %} {% highlight cshtml tabtitle="CSHTML" %} @@ -200,26 +148,42 @@ In the below example, we have **CustomerID** as a hidden column in the grid. Whi {% endhighlight %} {% endtabs %} -{% elsif page.publishingplatform == "aspnet-mvc" %} +![Show or hide columns while printing](../images/print/print-hide.png) + +## Limitations of printing large data + +Printing a large volume of data all at once in the grid can have certain limitations due to potential browser performance issues. Rendering numerous DOM elements on a single page can lead to browser slowdowns or even hang the browser. The grid offers a solution to manage extensive datasets through virtualization. However, it's important to note that virtualization for both rows and columns is not feasible during the printing process. + +If printing all the data remains a requirement, an alternative approach is recommended. Exporting the grid data to formats like [Excel](https://ej2.syncfusion.com/aspnetcore/documentation/grid/excel-export/excel-exporting) or [CSV](https://ej2.syncfusion.com/aspnetcore/documentation/grid/excel-export/excel-exporting) or [Pdf](https://ej2.syncfusion.com/aspnetcore/documentation/grid/pdf-export/pdf-export) is advised. This exported data can then be printed using non-web-based applications, mitigating the potential performance challenges associated with printing large datasets directly from the browser. + +## Retain grid styles while printing + +The Syncfusion ASP.NET Core Grid provides a [beforePrint](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event that allows you to customize the appearance and styles of the grid before it is sent to the printer. By handling this event, you can ensure that the grid retains its styles and appearance while printing. {% tabs %} -{% highlight razor tabtitle="CSHTML" %} -{% include code-snippet/grid/print/show-hide-columns/razor %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/grid/print/print-style/tagHelper %} {% endhighlight %} -{% highlight c# tabtitle="Show-hide.cs" %} -{% include code-snippet/grid/print/show-hide-columns/show-hide.cs %} +{% highlight c# tabtitle="print.cs" %} +{% include code-snippet/grid/print/print-style/print.cs %} {% endhighlight %} {% endtabs %} -{% endif %} - +![Retain grid styles while printing](../images/print/print-style.png) -## Limitations of Printing Large Data +## Print grid along with other components -When grid contains large number of data, printing all the data at once is not a best option for the browser performance. Because to render all the DOM elements in one page will produce performance issues in the browser. It leads to browser slow down or browser hang. Grid have option to handle large number of data by Virtualization. However while printing, it is not possible to use virtualization for rows and columns. +To print the Syncfusion ASP.NET Core Grid along with another component, such as a chart, you can use the [beforePrint](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html#Syncfusion_EJ2_Grids_Grid_BeforePrint) event of the grid. In this event, you can clone the content of the other component and append it to the print document. -If printing of all the data is still needed, we suggest to Export the grid to **Excel** or **CSV** or **Pdf** and then print it from another non-web based application. +Here is an example of how to print grid along with chart component: -## See Also +{% tabs %} +{% highlight cshtml tabtitle="CSHTML" %} +{% include code-snippet/grid/print/print-custom/tagHelper %} +{% endhighlight %} +{% highlight c# tabtitle="print.cs" %} +{% include code-snippet/grid/print/print-custom/print.cs %} +{% endhighlight %} +{% endtabs %} -* [How to Print the expanded state grid from all pages](./how-to/print-the-expanded-state-from-other-pages) +![Print grid along with other components](../images/print/print-custom.png) diff --git a/ej2-asp-core-mvc/grid/images/print/print-current.png b/ej2-asp-core-mvc/grid/images/print/print-current.png new file mode 100644 index 0000000000..1cc7f12905 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-current.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-custom.png b/ej2-asp-core-mvc/grid/images/print/print-custom.png new file mode 100644 index 0000000000..6c5f9d59a5 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-custom.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-external.png b/ej2-asp-core-mvc/grid/images/print/print-external.png new file mode 100644 index 0000000000..2bf6f02f50 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-external.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-hide.png b/ej2-asp-core-mvc/grid/images/print/print-hide.png new file mode 100644 index 0000000000..360e3a801a Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-hide.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-hierachy.png b/ej2-asp-core-mvc/grid/images/print/print-hierachy.png new file mode 100644 index 0000000000..af1ee3e927 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-hierachy.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-master.png b/ej2-asp-core-mvc/grid/images/print/print-master.png new file mode 100644 index 0000000000..597d52939c Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-master.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-preview.png b/ej2-asp-core-mvc/grid/images/print/print-preview.png new file mode 100644 index 0000000000..832b421681 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-preview.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-select.png b/ej2-asp-core-mvc/grid/images/print/print-select.png new file mode 100644 index 0000000000..4f8ec6e2c7 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-select.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print-style.png b/ej2-asp-core-mvc/grid/images/print/print-style.png new file mode 100644 index 0000000000..9ed9f18402 Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print-style.png differ diff --git a/ej2-asp-core-mvc/grid/images/print/print.png b/ej2-asp-core-mvc/grid/images/print/print.png new file mode 100644 index 0000000000..b00e9cfd5e Binary files /dev/null and b/ej2-asp-core-mvc/grid/images/print/print.png differ