var dm = ej.DataManager({
url: "/api/Orders/GetOrders",
adaptor: new ej.UrlAdaptor(),
enableCaching: false,
cachingPageSize: 10,
timeTillExpiration: 120000
});
$("#Grid1").ejGrid({
dataSource: dm,
……………..
toolbarSettings: {
showToolbar: true, toolbarItems: ['search', ej.Grid.ToolBarItems.ExcelExport, ej.Grid.ToolBarItems.WordExport, ej.Grid.ToolBarItems.PdfExport]
},
toolbarClick: function (args) {
if (args.itemName == "Excel Export") {
this.export("/api/Orders/ExcelExport");
args.cancel = true;
}
else if (args.itemName == "Word Export") {
this.export("/api/Orders/WordExport");
args.cancel = true;
}
else if (args.itemName == "PDF Export") {
this.export("/api/Orders/PdfExport");
args.cancel = true;
}
},
columns: [
……………..
]
});
</script>
Controller Page
<ActionName("ExcelExport")>
<HttpPost>
Public Sub ExcelExport()
Dim exp As ExcelExport = New ExcelExport()
Dim gridModel As String = HttpContext.Current.Request.Params("GridModel")
Dim obj As GridProperties = CType(Syncfusion.JavaScript.Utils.DeserializeToModel(GetType(GridProperties), gridModel), GridProperties)
Dim Db As NORTHWNDEntities = New NORTHWNDEntities()
Dim result = Db.Orders.ToList()
Dim excelExp As GridExcelExport = New GridExcelExport()
excelExp.FileName = "Export.xlsx"
excelExp.Excelversion = ExcelVersion.Excel2010
excelExp.Theme = "flat-saffron"
exp.Export(obj, result, excelExp)
End Sub
<ActionName("WordExport")>
<HttpPost>
Public Sub WordExport()
Dim exp As WordExport = New WordExport()
Dim gridModel As String = HttpContext.Current.Request.Params("GridModel")
Dim obj As GridProperties = CType(Syncfusion.JavaScript.Utils.DeserializeToModel(GetType(GridProperties), gridModel), GridProperties)
Dim Db As NORTHWNDEntities = New NORTHWNDEntities()
Dim result = Db.Orders.ToList()
Dim WordExp As GridWordExport = New GridWordExport()
WordExp.FileName = "Export.docx"
WordExp.Theme = "flat-saffron"
exp.Export(obj, result, WordExp)
End Sub
<ActionName("PdfExport")>
<HttpPost>
Public Sub PdfExport()
Dim exp As PdfExport = New PdfExport()
Dim gridModel As String = HttpContext.Current.Request.Params("GridModel")
Dim obj As GridProperties = CType(Syncfusion.JavaScript.Utils.DeserializeToModel(GetType(GridProperties), gridModel), GridProperties)
Dim Db As NORTHWNDEntities = New NORTHWNDEntities()
Dim result = Db.Orders.ToList()
Dim PdfExp As GridPdfExport = New GridPdfExport()
PdfExp.FileName = "Export.pdf"
PdfExp.Theme = "flat-saffron"
exp.Export(obj, result, PdfExp)
End Sub
|