-
Notifications
You must be signed in to change notification settings - Fork 804
Adding Excel Export
import * as Serenity from '@serenity-is/corelib'; import { Decorators, EntityGrid } from '@serenity-is/corelib'; import { saveAs } from 'file-saver'; //import { resolveUrl } from "@serenity-is/corelib/q"; import { MaintenanceFormsColumns, MaintenanceFormsRow, MaintenanceFormsService } from '../../ServerTypes/Maintenance'; import { MaintenanceFormsDialog } from './MaintenanceFormsDialog'; @Decorators.registerClass('MaintenanceApp.Maintenance.MaintenanceFormsGrid') export class MaintenanceFormsGrid extends EntityGrid { protected getColumnsKey() { return MaintenanceFormsColumns.columnsKey; } protected getDialogType() { return MaintenanceFormsDialog; } protected getRowDefinition() { return MaintenanceFormsRow; } protected getService() { return MaintenanceFormsService.baseUrl; }
protected getButtons() {
const buttons = super.getButtons();
buttons.push({
title: 'Export to Excel',
cssClass: 'export-xlsx-button',
onClick: () => this.onExportToExcel()
});
return buttons;
}
protected onExportToExcel() {
const request = this.getView().params as Serenity.ListRequest;
const url = Serenity.resolveUrl("~/services/Maintenance/MaintenanceForms/ListExcel");
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(request)
})
.then(response => response.blob()) // Convert response to Blob
.then(blob => {
saveAs(blob, "MaintenanceFormsList.xlsx");
})
.catch(error => {
console.error("Export failed:", error);
alert("Failed to export to Excel.");
});
}
}
Copyright © Serenity Platform 2017-present. All rights reserved.
Documentation | Serene Template | Live Demo | Premium Support | Issues | Discussions