Provides exporting support for @angular/material tables
npm install mat-table-exporter !Total Downloads
This package is to make MatTable components exportable in excel, csv, txt and json formats. Pagination is also supported. Applying MatTableExporter directive to your MatTable is enough to make it exportable. The directive uses different exporter services for different exporting types. You can also implement your own exporter and use it for your custom exporting requirements.
This project employs xlsx sheetjs, which is a great library and mature enough for the excel creation itself. In order to achieve a cross-browser file saving capability FileSaverjs is employed.
The MatTableExporter directive inside this package is a cdk-table-exporter subtype and provides support for angular material's cdkTable.
cdk-table-exporter facilitates the common exporting related functionalities for CdkTable implementations abstracting the behavior that can change among different CdkTables.
If you are employing angular material in your project. Install mat-table-exporter
```
npm install mat-table-exporter`
NOTE: Angular versions older than Angular 8 should install mat-table-exporter@1.2.5`
npm install mat-table-exporter@1.2.5
For Angular versions between 8-13 (inclusive), please install mat-table-exporter@10.2.4
``
npm install mat-table-exporter@10.2.4
After installing mat-table-exporter import MatTableExporterModule in your ngModule
``
import { MatTableExporterModule } from 'mat-table-exporter';``
@NgModule({
imports: [
...
MatTableExporterModule
],
]})
matTableExporter is the directive selector.`html`
`html`
##### * Stackblitz demo: mte-demo.
##### * Stackblitz demo of custom exporter mte-cex-demo.
| Input/Output | Property | Type | Description |
| --- | --- | --- | --- |
| @Input | hiddenColumns | Array | (Optional) The indexes of the columns that are not wanted in the output file |@Input
| | exporter | Exporter | (Optional) The actual exporting implementation that defines the strategy to be applied to the rows extracted from MatTable. |@Output
| | exportStarted | EventEmitter | (Optional) Event that's fired when the export started |@Output
| | exportCompleted | EventEmitter | (Optional) Event that's fired when the export completed |
| Method | Description |
|----------|-------------|
| exportTable(exportType?: ExportType, options?: Options) | Called to trigger the export of MatTable|toggleRow(index: number)
| | Called to mark the row for selection export, if the requirement is to export only selected rows. Having no rows selected means export everything |resetToggleRow()
| | Resets all the rows toggled for exporting |
`js`
export enum ExportType {
XLS = 'xls',
XLSX = 'xlsx',
CSV = 'csv',
TXT = 'txt',
JSON = 'json',
OTHER = 'other'
}
| Property | Type | Description |
|----------|--------|-------------|
| fileName | string |(Optional) Name of the exported file|
| Property | Type | Description |
|----------|--------|-------------|
| delimiter | string |(Optional) Field separator @default ,|
| Property | Type | Description |
|----------|--------|-------------|
| fileName | string |(Optional) Name of the exported file|'base64', 'binary', 'buffer', 'file', 'array', 'string'
| type | |(Optional) Output data encoding|boolean
| bookSST | |(Optional) Generate Shared String Table @default false|string
| sheet | |(Optional) Name of the exported sheet|boolean
| compression | |(Optional) Use ZIP compression for ZIP-based formats @default false|boolean
| ignoreEC | |(Optional) Suppress "number stored as text" errors in generated files @default true|Properties
| Props | |(Optional) Workbook properties like Author, Title, Subject etc.|Array
| columnWidths | | (Optional) Column widths in maximum char |
Even if Xlsx is loaded dynamically, it is heavy by nature. If you'd like to benefit the extra minified version of xlsx (xlsx.mini.min; Doesn't support some features like .xls exporting) you can configure the module as shown below:
``
@NgModule({
imports: [
...
MatTableExporterModule.forRoot({xlsxLightWeight: true}),
],
]})
1. Do `npm install` in `ng-material-extensions` directory`
2. Do npm install` in `ng-material-extensions\projects\cdk-table-exporter` directory`
3. Do npm install` in `ng-material-extensions\projects\mat-table-exporter` directory`
4. Go to ng-material-extensions` directory`
5. Build both of the exporter packages:`
ng build cdk-table-exporter``
ng build mat-table-exporter`
6. You can run the showcase application and see your changes in action. In ng-material-extensions` run `ng s -o``
Feel free to show your support. Donating supporters will be added into Supporters section inside the README.md of the repository.
 -> Become a star-gazer, giving a star at Github
 -> Donate in crypto currencies
Apache-2.0