Having trouble getting help?
Contact Support
Contact Support
Print in ASP.NET MVC Pivot Table Component
4 Aug 20232 minutes to read
The rendered pivot table can be printed directly from the browser by invoking the print
method from the grid’s instance. The below sample code illustrates the print option being invoked by 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();
}
Similarly, to print the pivot chart, use the print
method from the chart’s instance. The below sample code illustrates the print option being invoked by an external button click.
To display the pivot chart, set the
PivotViewDisplayOption
property to either Chart or Both.
@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();
}