exportSelectedRow() {
const selectedRows = this.myGrid.selectedRows;
if (selectedRows.length > 0) {
const rowData = selectedRows[0];
this.fileTemplateService.GetFileData(selectedRows[0].fileCode, selectedRows[0].dataFileToProcessDetailsId)
.subscribe({
next: (res) => {
if (res.length == 0) {
this.notificationService.showMessage(AlertMessageType.Error, AppConstant.noFileInfo);
}
else {
const headers = Object.keys(res[0]);
const rows = res.map(obj => Object.values(obj))
const csvContent = headers.join(',') + '\n' + rows.map(row => row.join(',')).join('\n');
const fileName = `${selectedRows[0].fileName.slice(0, -4)}.csv`;
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
this.saveCSVFile(blob, fileName);
}
}, error: (err) => {
this.notificationService.showMessage(AlertMessageType.Error, AppConstant.fileDataError);
}
})
}
}
saveCSVFile(blob: Blob, fileName: string) {
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
}