diff --git a/src/app/components/common/shared.ts b/src/app/components/common/shared.ts index 03c3404f3e7..abcfc26a7c0 100644 --- a/src/app/components/common/shared.ts +++ b/src/app/components/common/shared.ts @@ -81,6 +81,7 @@ export class Column implements AfterContentInit{ @Input() scope: string; @Input() style: any; @Input() styleClass: string; + @Input() exportable: boolean = true; @Input() headerStyle: any; @Input() headerStyleClass: string; @Input() bodyStyle: any; diff --git a/src/app/components/datatable/datatable.ts b/src/app/components/datatable/datatable.ts index f00b72fd952..ce7c3ad6ad5 100644 --- a/src/app/components/datatable/datatable.ts +++ b/src/app/components/datatable/datatable.ts @@ -2523,8 +2523,9 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni //headers for(let i = 0; i < this.columns.length; i++) { - if(this.columns[i].field) { - csv += '"' + (this.columns[i].header || this.columns[i].field) + '"'; + let column = this.columns[i]; + if(column.exportable && column.field) { + csv += '"' + (column.header || column.field) + '"'; if(i < (this.columns.length - 1)) { csv += this.csvSeparator; @@ -2536,8 +2537,9 @@ export class DataTable implements AfterViewChecked,AfterViewInit,AfterContentIni data.forEach((record, i) => { csv += '\n'; for(let i = 0; i < this.columns.length; i++) { - if(this.columns[i].field) { - csv += '"' + this.resolveFieldData(record, this.columns[i].field) + '"'; + let column = this.columns[i]; + if(column.exportable && column.field) { + csv += '"' + this.resolveFieldData(record, column.field) + '"'; if(i < (this.columns.length - 1)) { csv += this.csvSeparator; diff --git a/src/app/showcase/components/datatable/datatabledemo.html b/src/app/showcase/components/datatable/datatabledemo.html index 11bd3689f61..f0e9a255bb7 100644 --- a/src/app/showcase/components/datatable/datatabledemo.html +++ b/src/app/showcase/components/datatable/datatabledemo.html @@ -214,6 +214,12 @@

Properties

null Style class of the column, can be override with headerStyleClass, bodyStyleClass and footerStyleClass. + + exportable + boolean + true + Whether the column is included during data export. + headerStyle object @@ -912,6 +918,8 @@

Data Export

<button type="button" pButton icon="fa-file-o" iconPos="left" label="CSV" (click)="dt.exportCSV({selectionOnly:true})"></button> +

In order to exclude a column from the csv, use [exportable]="false" on p-column.

+

See the live example.

Scrolling