Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not take into account non exportable fields for csv separators #14416

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 23 additions & 34 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2263,43 +2263,32 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
}
}

//headers
for (let i = 0; i < (<any[]>columns).length; i++) {
let column = (<any[]>columns)[i];
if (column.exportable !== false && column.field) {
csv += '"' + this.getExportHeader(column) + '"';
const exportableColumns: any[] = (<any[]>columns).filter(column => column.exportable !== false && column.field);

if (i < (<any[]>columns).length - 1) {
csv += this.csvSeparator;
}
}
}
//headers
csv += exportableColumns.map(column => '"' + this.getExportHeader(column) + '"').join(this.csvSeparator);

//body
data.forEach((record: any, i: number) => {
csv += '\n';
for (let i = 0; i < (<any[]>columns).length; i++) {
let column = (<any[]>columns)[i];
if (column.exportable !== false && column.field) {
let cellData = ObjectUtils.resolveFieldData(record, column.field);

if (cellData != null) {
if (this.exportFunction) {
cellData = this.exportFunction({
data: cellData,
field: column.field
});
} else cellData = String(cellData).replace(/"/g, '""');
} else cellData = '';

csv += '"' + cellData + '"';

if (i < (<any[]>columns).length - 1) {
csv += this.csvSeparator;
}
}
}
});
const body = data.map((record: any) =>
exportableColumns.map(column => {
let cellData = ObjectUtils.resolveFieldData(record, column.field);

if (cellData != null) {
if (this.exportFunction) {
cellData = this.exportFunction({
data: cellData,
field: column.field
});
} else cellData = String(cellData).replace(/"/g, '""');
} else cellData = '';

return '"' + cellData + '"';
}).join(this.csvSeparator)
).join('\n');

if (body.length) {
csv += '\n' + body;
}

let blob = new Blob([csv], {
type: 'text/csv;charset=utf-8;'
Expand Down