DataTable Export
-
- Posts: 84
- Joined: 06 Sep 2022, 08:59
For what it's worth, I made a invisible <DataTable> with downloadable data, that was intentionally a little bit different than what's visible (more columns, ungrouped, things like that). I also wanted to include an accurate timestamp in the filename. Turned out a bit like this. Hope it helps someone.
Code: Select all
<template :v-show="false">
<DataTable
ref="exporttable"
:key="exportfilename"
:value="exportdata"
:exportFilename="exportfilename"
>
<Column
v-for="(col, index) of chosencolumns"
:field="col.field"
:header="col.header"
:key="col.field + '_x_' + index"
>
</Column>
</DataTable>
</template>
Code: Select all
<Button
label="Download"
icon="pi pi-file-excel"
loadingIcon="pi pi-spin pi-cog"
:loading="loading.download"
class="p-button p-button-secondary"
@click="download"
/>
Code: Select all
download() {
this.loading.download = true;
this.exportdata = this.exportfilter();
const d = new Date();
let fn = "Export_";
fn += d.toISOString().substring(0, 19);
this.exportfilename = fn.replace(/[T:-]/g, "");
this.$nextTick()
.then(() => {
this.$refs.exporttable.exportCSV();
})
.then(() => {
this.exportdata = [];
this.exportfilename = d.toISOString();
this.loading.download = false;
});
},
-
- Information
-
Who is online
Users browsing this forum: No registered users and 17 guests