ejGrid

22 Feb 201810 minutes to read

Essential Grid is export as a PDF, Word or Excel document by using services . Data from a remote server can be bound to ejGrid using ejDataManager widget.

Northwnd service

Description

To retrieve the records from Orders table in Northwnd service.

URL

http://mvc.syncfusion.com/Services/Northwnd.svc/

Parameter

$top 10 $filter EmployeeID eq 5 $skip 2

Request

  • JS
  • var dataManger = new ej.DataManager(
    {
        url: "http://mvc.syncfusion.com/Services/Northwnd.svc/"
    });

    Response

    Code: 200

    Content-Type: application/json;odata=verbose;charset=utf-8

    Response (JSON):

  • JS
  • {
    	    'd': [
                {
                    '_metadata': {
                        'id': 'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)',
                        'uri': 'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)',
                        'type': 'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)'
                    },
                    'Customer': {
                        '_deferred': {
                            'uri':'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)/Customer'
                        }
                    },
                    'Employee': {
                        '_deferred': {
                            'uri': 'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)/Employee'
                        }
                    },
                    'Order_Details': {
                        '_deferred': {
                            'uri': 'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)/Order_Details'
                        },
                        'Shipper': {
                            '_deferred': {
                                'uri': 'http://mvc.syncfusion.com/Services/Northwnd.svc/Orders(10248)/Shipper'
                            },
                            'OrderID': 10248,
                            'CustomerID': 'VINET',
                            'EmployeeID': 1,
                            'OrderDate': '/Date(1423027800000)/',
                            'RequiredDate': '/Date(1424951652613)/',
                            'ShippedDate': '/Date(1424608518217)/',
                            'ShipVia': null,
                            'Freight': '6.0000',
                            'ShipName': 'SURINDER',
                            'ShipAddress': 'OLDTOWN',
                            'ShipCity': 'STOCKHOLM',
                            'ShipRegion': 'New Delhi HO',
                            'ShipPostalCode': '110001',
                            'ShipCountry':'SWEDEN'
                        },
                    },
                },
    
                //... 9 more records
    	    ]
    	}

    Exporting service

    Description

    To export grid data as Excel, Word or PDF document.

    URL

    http://js.syncfusion.com/ExportingServices/api/JSGridExport/ExcelExport
    http://js.syncfusion.com/ExportingServices/api/JSGridExport/WordExport
    http://js.syncfusion.com/ExportingServices/api/JSGridExport/PdfExport

    Parameter

    type URL multipleExport
    Excel http://js.syncfusion.com/ExportingServices/api/JSGridExport/ExcelExport false
    Word http://js.syncfusion.com/ExportingServices/api/JSGridExport/WordExport false
    PDF http://js.syncfusion.com/ExportingServices/api/JSGridExport/PdfExport false

    Request

    Essential grid exporting in JavaScript platform

  • JS
  • $(function() {
        $("#Grid").ejGrid({
            dataSource: window.gridData,
            allowPaging: true,
            toolbarSettings: {
                showToolbar: true,
                toolbarItems: [ej.Grid.ToolBarItems.ExcelExport, ej.Grid.ToolBarItems.WordExport, ej.Grid.ToolBarItems.PdfExport]
            },
            toolbarClick: function(e) {
                this.exportGrid = this["export"];
                if (e.itemName == "Excel Export") {
                    this.exportGrid('http://js.syncfusion.com/ExportingServices/api/JSGridExport/ExcelExport')
                    e.cancel = true;
                } else if (e.itemName == "Word Export") {
                    this.exportGrid('http://js.syncfusion.com/ExportingServices/api/JSGridExport/WordExport')
                    e.cancel = true;
                } else if (e.itemName == "PDF Export") {
                    this.exportGrid('http://js.syncfusion.com/ExportingServices/api/JSGridExport/PdfExport')
                    e.cancel = true;
                }
            },
        })
    
    })

    Essential grid exporting in C#

  • C#
  • public void ExportToExcel(string GridModel)
            {
                ExcelExport exp = new ExcelExport();
                var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList();
                GridProperties obj = ConvertGridObject(GridModel);
                exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");
            }
            public void ExportToWord(string GridModel)
            {
                WordExport exp = new WordExport();
                var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList();
                GridProperties obj = ConvertGridObject(GridModel);
                exp.Export(obj, DataSource, "Export.docx", false, false, "flat-saffron");
            }
            public void ExportToPdf(string GridModel)
            {
                PdfExport exp = new PdfExport();
                var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList();
                GridProperties obj = ConvertGridObject(GridModel);
                exp.Export(obj, DataSource, "Export.pdf", false, false, "flat-saffron");
            }

    Response

    Code: 200

    Content-Type: application/octet-stream