Fixed #1845 - Add data param to exportCSV method on DataTable
parent
8f8c97f8ad
commit
e08fd2d1d0
|
@ -1032,9 +1032,10 @@ export declare type DataTableEmits = {
|
|||
declare class DataTable extends ClassComponent<DataTableProps, DataTableSlots, DataTableEmits> {
|
||||
/**
|
||||
* Exports the data to CSV format.
|
||||
* @param {DataTableExportCSVOptions} options - Export options.
|
||||
* @param {DataTableExportCSVOptions} [options] - Export options.
|
||||
* @param {Object[]} [data] - Custom exportable data. This param can be used on lazy dataTable.
|
||||
*/
|
||||
exportCSV: (options?: DataTableExportCSVOptions) => void;
|
||||
exportCSV: (options?: DataTableExportCSVOptions, data?: any[]) => void;
|
||||
}
|
||||
|
||||
declare module '@vue/runtime-core' {
|
||||
|
|
|
@ -997,14 +997,17 @@ export default {
|
|||
|
||||
this.$emit('update:selection', _selection);
|
||||
},
|
||||
exportCSV(options) {
|
||||
let data = this.processedData;
|
||||
exportCSV(options, data) {
|
||||
let csv = '\ufeff';
|
||||
|
||||
if (options && options.selectionOnly)
|
||||
data = this.selection || [];
|
||||
else if (this.frozenValue)
|
||||
data = data ? [...this.frozenValue, ...data] : this.frozenValue;
|
||||
if (!data) {
|
||||
data = this.processedData;
|
||||
|
||||
if (options && options.selectionOnly)
|
||||
data = this.selection || [];
|
||||
else if (this.frozenValue)
|
||||
data = data ? [...this.frozenValue, ...data] : this.frozenValue;
|
||||
}
|
||||
|
||||
//headers
|
||||
let headerInitiated = false;
|
||||
|
@ -1055,28 +1058,7 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
let blob = new Blob([csv], {
|
||||
type: 'text/csv;charset=utf-8;'
|
||||
});
|
||||
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
navigator.msSaveOrOpenBlob(blob, this.exportFilename + '.csv');
|
||||
}
|
||||
else {
|
||||
let link = document.createElement("a");
|
||||
link.style.display = 'none';
|
||||
document.body.appendChild(link);
|
||||
if (link.download !== undefined) {
|
||||
link.setAttribute('href', URL.createObjectURL(blob));
|
||||
link.setAttribute('download', this.exportFilename + '.csv');
|
||||
link.click();
|
||||
}
|
||||
else {
|
||||
csv = 'data:text/csv;charset=utf-8,' + csv;
|
||||
window.open(encodeURI(csv));
|
||||
}
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
DomHandler.exportCSV(csv, this.exportFilename);
|
||||
},
|
||||
resetPage() {
|
||||
this.d_first = 0;
|
||||
|
|
|
@ -507,5 +507,30 @@ export default {
|
|||
|
||||
isTouchDevice() {
|
||||
return (('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0));
|
||||
},
|
||||
|
||||
exportCSV(csv, filename) {
|
||||
let blob = new Blob([csv], {
|
||||
type: 'application/csv;charset=utf-8;'
|
||||
});
|
||||
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
navigator.msSaveOrOpenBlob(blob, filename + '.csv');
|
||||
}
|
||||
else {
|
||||
let link = document.createElement("a");
|
||||
if (link.download !== undefined) {
|
||||
link.setAttribute('href', URL.createObjectURL(blob));
|
||||
link.setAttribute('download', filename + '.csv');
|
||||
link.style.display = 'none';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
else {
|
||||
csv = 'data:text/csv;charset=utf-8,' + csv;
|
||||
window.open(encodeURI(csv));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ export declare class DomHandler {
|
|||
static isIOS(): boolean;
|
||||
static isAndroid(): boolean;
|
||||
static isTouchDevice(): boolean;
|
||||
static exportCSV(csv: any, filename: string): void;
|
||||
}
|
||||
|
||||
export declare class ObjectUtils {
|
||||
|
|
Loading…
Reference in New Issue