Show Spinner on Grid when Exporting
17 Feb 20222 minutes to read
You can show/ hide spinner component while exporting the grid using showSpinner/ hideSpinner methods. You can use ToolbarClick
event to show spinner before exporting and hide a spinner in the PdfExportComplete
or ExcelExportComplete
event after the exporting.
In the ToolbarClick
event, based on the parameter args.item.id as Grid_pdfexport or Grid_excelexport we can call the showSpinner method from grid instance.
In the PdfExportComplete
or ExcelExportComplete
event, We can call the hideSpinner method.
In the below demo, we have rendered the default spinner component when exporting the grid.
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).AllowPdfExport().AllowExcelExport().ToolbarClick("toolbarClick").PdfExportComplete("pdfExportComplete").ExcelExportComplete("excelExportComplete").Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer Name").Visible(false).Width("150").Add();
col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add();
col.Field("ShipCity").HeaderText("ShipCity").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width("120").Add();
}).AllowPaging().Toolbar(new List<string>() { "PdfExport", "ExcelExport" }).Render()
<script>
function toolbarClick(args) {
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (args.item.id === 'Grid_pdfexport') {
gridObj.showSpinner();
gridObj.pdfExport();
}
else if (args.item.id === 'Grid_excelexport') {
gridObj.showSpinner();
gridObj.excelExport();
}
}
function pdfExportComplete(args) {
this.hideSpinner();
}
function excelExportComplete(args) {
this.hideSpinner();
}
</script>
public IActionResult Index()
{
var Order = OrderDetails.GetAllRecords();
ViewBag.DataSource = Order;
return View();
}