Articles in this section
Category / Section

How to export Grid with Custom Summary in ASP.NET MVC application?

1 min read

This Knowledge Base explains you how to use Custom Summary while exporting Grid to Word, Excel and Pdf file formats.

Solution:

Create Grid sample for displaying Custom summary. While exporting the Grid, the custom summary will be added to Grid through QuerycustomSummaryinfo event of GridPdfExport, GridWordExport, GridExcelExport.

RAZOR

@(Html.EJ().Grid<object>("Editing")
           .Datasource((IEnumerable<object>)ViewBag.datasource)
           .ShowSummary()
           .SummaryRow(row =>
                    {
                        row.Title("Currency").SummaryColumns(col => { col.SummaryType(SummaryType.Custom).CustomSummaryValue("currency").DisplayColumn("Freight").Format("{0:C2}").Add(); }).Add();
                    })                             
           .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
                {
                    items.AddTool(ToolBarItems.ExcelExport);
                    items.AddTool(ToolBarItems.WordExport);
                    items.AddTool(ToolBarItems.PdfExport);
                }))
           .Columns(col =>
            {
                col.Field("OrderID").Add();
                col.Field("CustomerID").Add();
                col.Field("EmployeeID").Add();
                col.Field("Freight").Format("{0:C2}").Add();
            })
)
<script type="text/javascript">
    function currency() {
        var rs = 100000;
        var dol = 0.017;
        return (rs * dol);
    }
</script>

 

C#

public void ExportToExcel(string GridModel)
        {
            GridExcelExport exp1 = new GridExcelExport();
            ExcelExport exp = new ExcelExport();
            var DataSource = order;
            GridProperties obj = ConvertGridObject(GridModel);
            exp1.QueryCustomSummaryInfo = QueryCellInfo;
            exp1.Theme = "default-theme";            
            exp1.FileName = "Export.xlsx";            
            exp.Export(obj, DataSource, exp1);           
        }
public void ExportToWord(string GridModel)
        {
            WordExport exp = new WordExport();
            GridWordExport exp1 = new GridWordExport();           
            var DataSource = order;
            GridProperties obj = ConvertGridObject(GridModel);
            exp1.QueryCustomSummaryInfo = QueryCellInfo;
            exp1.Theme = "default-theme";
            exp1.FileName = "Export.docx";
            exp.Export(obj, DataSource, exp1);           
        }
public void ExportToPdf(string GridModel)
        {
            GridPdfExport exp1 = new GridPdfExport();            
            PdfExport exp = new PdfExport();
            var DataSource = order;
            GridProperties obj = ConvertGridObject(GridModel);
            exp1.QueryCustomSummaryInfo = QueryCellInfo;
            exp1.Theme = "default-theme";
            exp1.FileName = "Export.pdf";
            exp.Export(obj, DataSource, exp1);
        }
private object QueryCellInfo(IQueryable arg1, SummaryColumn arg2)
        {
            var rs = 100000;
            var dol = 0.017;
            return (rs * dol);
        }

 

ASPX

<ej:Grid ID="FlatGrid" runat="server" OnServerPdfExporting="FlatGrid_ServerPdfExporting" OnServerWordExporting="FlatGrid_ServerWordExporting" OnServerExcelExporting="FlatGrid_ServerExcelExporting">
            <ToolbarSettings ShowToolbar="true" ToolbarItems="pdfExport”,”excelExport”,”wordExport"></ToolbarSettings>
              <SummaryRows>
                <ej:SummaryRow Title="Currency" >
                    <SummaryColumn>
                        <ej:SummaryColumn SummaryType="Custom" CustomSummaryValue="currency" DisplayColumn="Freight"
                            Format="{0:C2}" />
                    </SummaryColumn>
                </ej:SummaryRow>
            </SummaryRows>
            
    <Columns>
                <ej:Column Field="OrderID" HeaderText="Order ID" />
                <ej:Column Field="CustomerID" HeaderText="Customer ID" />
                <ej:Column Field="EmployeeID" HeaderText="Employee ID/>
                <ej:Column Field="Freight" HeaderText="Freight" Format="{0:C2}"/>                
    </Columns>  
</ej:Grid>
        
 <script type="text/javascript">
        function currency() 
        {
                 var rs = 100000;
                 var dol = 0.017;
                 return (rs * dol);
        }           
    </script>

 

C#

protected void FlatGrid_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
           GridPdfExport exp1 = new GridPdfExport();  
            PdfExport exp = new PdfExport();
            exp1.QueryCustomSummaryInfo = QueryCellInfo;
            exp1.Theme = "default-theme";
            exp1.FileName = "Export.pdf";            
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, exp1);            
        }
protected void FlatGrid_ServerWordExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
            GridWordExport exp1 = new GridWordExport();  
            WordExport exp = new WordExport();
            exp1.QueryCustomSummaryInfo = QueryCellInfo;
            exp1.Theme = "default-theme";
            exp1.FileName = "Export.docx";            
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, exp1);            
        }
protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
        {
           GridExcelExport exp1 = new GridExcelExport();  
            ExcelExport exp = new ExcelExport();
            exp1.QueryCustomSummaryInfo = QueryCellInfo;
            exp1.Theme = "default-theme";
            exp1.FileName = "Export.xlsx";            
            exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, exp1);            
        }
private object QueryCellInfo(IQueryable arg1, SummaryColumn arg2)
        {     
            var rs = 100000;
            var dol = 0.017;
            return (rs * dol);
        }
            

 

Above Code example will export the Grid with Custom Summary in it as shown below.

Figure: Exported Grid with Custom Summary in Pdf File Format. 


Conclusion

I hope you enjoyed learning about how to export Grid with Custom Summary in ASP.NET MVC application.

You can refer to our ASP.NET MVC Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
You can also explore our 
ASP.NET MVC Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied