File

src/app/core/export/export-data-directive/export-data.directive.ts

Description

A directive that can be attached to a html element, commonly a button. Usage:

Example :
 <button
   mat-stroked-button
   [appExportData]="data"
   format="csv"
 >
   Export CSV
 </button

Metadata

Index

Methods
Inputs
HostListeners

Constructor

constructor(downloadService: DownloadService)
Parameters :
Name Type Optional
downloadService DownloadService No

Inputs

appExportData
Type : any
Default value : []

data to be exported

exportConfig
Type : ExportColumnConfig[]

(Optional) definition of fields to be exported.

If not provided, all properties will be included in the export.

filename
Type : string
Default value : "exportedData"

filename for the download of the exported data

format
Type : FileDownloadFormat
Default value : "csv"

What kind of data should be export? Currently implemented are 'json', 'csv'

HostListeners

click

Methods

click
click()
Decorators :
@HostListener('click')
Returns : any
import { Directive, HostListener, Input } from "@angular/core";
import { ExportColumnConfig } from "../data-transformation-service/export-column-config";
import {
  DownloadService,
  FileDownloadFormat,
} from "../download-service/download.service";

/**
 * A directive that can be attached to a html element, commonly a button.
 * Usage:
 * ```html
 *  <button
 *    mat-stroked-button
 *    [appExportData]="data"
 *    format="csv"
 *  >
 *    Export CSV
 *  </button
 *
 * ```
 */
@Directive({
  selector: "[appExportData]",
  standalone: true,
})
export class ExportDataDirective {
  /** data to be exported */
  @Input("appExportData") data: any = [];

  /** What kind of data should be export? Currently implemented are 'json', 'csv' */
  @Input() format: FileDownloadFormat = "csv";

  /** filename for the download of the exported data */
  @Input() filename: string = "exportedData";

  /**
   * (Optional) definition of fields to be exported.
   *
   * If not provided, all properties will be included in the export.
   */
  @Input() exportConfig: ExportColumnConfig[];

  constructor(private downloadService: DownloadService) {}

  @HostListener("click")
  click() {
    return this.downloadService.triggerDownload(
      this.data,
      this.format,
      this.filename,
      this.exportConfig,
    );
  }
}

results matching ""

    No results matching ""