diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index e55d0e3b593..0f79301549d 100755 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -283,6 +283,8 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable @Input() exportFunction; + @Input() exportHeader: string; + @Input() stateKey: string; @Input() stateStorage: string = 'session'; @@ -1676,6 +1678,10 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable this.clear(); } + getExportHeader(column) { + return column[this.exportHeader] || column.header || column.field; + } + public exportCSV(options?: any) { let data; let csv = ''; @@ -1696,7 +1702,7 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable for (let i = 0; i < columns.length; i++) { let column = columns[i]; if (column.exportable !== false && column.field) { - csv += '"' + (column.header || column.field) + '"'; + csv += '"' + this.getExportHeader(column) + '"'; if (i < (columns.length - 1)) { csv += this.csvSeparator; diff --git a/src/app/showcase/components/table/tabledemo.html b/src/app/showcase/components/table/tabledemo.html index 282f36249d9..db1d19ba430 100755 --- a/src/app/showcase/components/table/tabledemo.html +++ b/src/app/showcase/components/table/tabledemo.html @@ -2212,8 +2212,6 @@
Data Export
} } - -

See the live example.

Scrolling
@@ -3362,6 +3360,12 @@
Properties
null Configures how much buffer space to render back up to when it detects that more buffer is required. + + exportHeader + string + null + Custom export header of the column to be exported as CSV. + diff --git a/src/app/showcase/components/table/tableexportdemo.html b/src/app/showcase/components/table/tableexportdemo.html index a3d6d1afedf..67b14742791 100755 --- a/src/app/showcase/components/table/tableexportdemo.html +++ b/src/app/showcase/components/table/tableexportdemo.html @@ -8,7 +8,7 @@

Table Export

- +
@@ -46,7 +46,7 @@

Table Export

-<p-table #dt [columns]="cols" [value]="products" selectionMode="multiple" [(selection)]="selectedProducts" responsiveLayout="scroll"> +<p-table #dt [columns]="cols" [value]="products" selectionMode="multiple" [(selection)]="selectedProducts" responsiveLayout="scroll" [exportHeader]="'customExportHeader'"> <ng-template pTemplate="caption"> <div class="flex"> <button type="button" pButton pRipple icon="pi pi-file" (click)="dt.exportCSV()" class="mr-2" pTooltip="CSV" tooltipPosition="bottom"></button> @@ -97,7 +97,7 @@

Table Export

this.productService.getProductsSmall().then(data => this.products = data); this.cols = [ - { field: 'code', header: 'Code' }, + { field: 'code', header: 'Code', customExportHeader: 'Product Code' }, { field: 'name', header: 'Name' }, { field: 'category', header: 'Category' }, { field: 'quantity', header: 'Quantity' } diff --git a/src/app/showcase/components/table/tableexportdemo.ts b/src/app/showcase/components/table/tableexportdemo.ts index f514e76e64a..94e9b231211 100755 --- a/src/app/showcase/components/table/tableexportdemo.ts +++ b/src/app/showcase/components/table/tableexportdemo.ts @@ -22,7 +22,7 @@ export class TableExportDemo implements OnInit { this.productService.getProductsSmall().then(data => this.products = data); this.cols = [ - { field: 'code', header: 'Code' }, + { field: 'code', header: 'Code', customExportHeader: 'Product Code' }, { field: 'name', header: 'Name' }, { field: 'category', header: 'Category' }, { field: 'quantity', header: 'Quantity' }