Page 1 of 1

DataTable Export

Posted: 07 Sep 2022, 21:00
by XaviiP7
Como cambiar el nombre del archivo a descargar, enviandolo desde una variable.?

Re: DataTable Export

Posted: 16 Sep 2022, 13:09
by bahadirsofuoglu
Hi,
You can use exportFilename prop.

Code: Select all

<Datatable exportFilename="yourFileName" />

Re: DataTable Export

Posted: 26 Sep 2022, 17:05
by Searerva
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;
        });
    },

Re: DataTable Export

Posted: 27 Sep 2022, 21:58
by XaviiP7
Thanks, it solved myy doubts