Print in ASP.NET MVC Pivot Table
9 Sep 20262 minutes to read
The ASP.NET MVC Pivot Table component supports print functionality, allowing users to print the current state of the pivot table or pivot chart. This feature enables users to generate hard copies of pivot table reports for convenient review and data sharing.
Print pivot table
Call the print method on the underlying Grid instance (accessed via the grid property of the pivotObj ref) to print the rendered pivot table. The Grid control captures the current state of the pivot table, including all applied filters, sorting, and formatting. The sample code below demonstrates how to trigger the print operation using an external button click.
@using Syncfusion.EJ2.PivotView
@Html.EJS().Button("print").Content("Print").IsPrimary(true).Render()
@Html.EJS().PivotView("PivotView").Height("300").DataSourceSettings(dataSourceSettings => dataSourceSettings.DataSource((IEnumerable<object>)ViewBag.DataSource).ExpandAll(false)
.FormatSettings(formatsettings =>
{
formatsettings.Name("Amount").Format("C0").Add();
}).Rows(rows =>
{
rows.Name("Country").Add(); rows.Name("Products").Add();
}).Columns(columns =>
{
columns.Name("Year").Caption("Year").Add(); columns.Name("Quarter").Add();
}).Values(values =>
{
values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Add();
})).Render()
<script>
var pivotObj;
document.getElementById('print').onclick = function () {
pivotObj = document.getElementById('PivotView').ej2_instances[0];
pivotObj.grid.print();
}
</script>public ActionResult Index()
{
var data = GetPivotData();
ViewBag.DataSource = data;
return View();
}Print pivot chart
Call the print method on the underlying Chart instance (accessed via the chart property of the PivotViewComponent ref) to print the pivot chart. The Chart control preserves colors, legends, and data labels in the printed output.
Set the
PivotViewDisplayOptionproperty to Chart or Both to display the pivot chart.
The sample below prints the pivot chart when an external button is clicked.
@using Syncfusion.EJ2.PivotView
@Html.EJS().Button("print").Content("Print").IsPrimary(true).Render()
@Html.EJS().PivotView("PivotView").Height("300").DataSourceSettings(dataSourceSettings => dataSourceSettings.DataSource((IEnumerable<object>)ViewBag.DataSource).ExpandAll(false)
.FormatSettings(formatsettings =>
{
formatsettings.Name("Amount").Format("C0").Add();
}).Rows(rows =>
{
rows.Name("Country").Add(); rows.Name("Products").Add();
}).Columns(columns =>
{
columns.Name("Year").Caption("Year").Add(); columns.Name("Quarter").Add();
}).Values(values =>
{
values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Add();
})).DisplayOption(new PivotViewDisplayOption { View = View.Chart }).ChartSettings(chartSettings => chartSettings.ChartSeries(chartSeries => chartSeries.Type(ChartSeriesType.Column))).Render()
<script>
var pivotObj;
document.getElementById('print').onclick = function () {
pivotObj = document.getElementById('PivotView').ej2_instances[0];
pivotObj.chart.print();
}
</script>public ActionResult Index()
{
var data = GetPivotData();
ViewBag.DataSource = data;
return View();
}