DataTable Export

UI Components for Vue
Post Reply
XaviiP7
Posts: 7
Joined: 30 Aug 2022, 20:33

07 Sep 2022, 21:00

Como cambiar el nombre del archivo a descargar, enviandolo desde una variable.?

bahadirsofuoglu
Posts: 26
Joined: 06 Sep 2022, 08:59

16 Sep 2022, 13:09

Hi,
You can use exportFilename prop.

Code: Select all

<Datatable exportFilename="yourFileName" />

Searerva
Posts: 6
Joined: 15 Sep 2022, 11:55

26 Sep 2022, 17:05

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;
        });
    },

XaviiP7
Posts: 7
Joined: 30 Aug 2022, 20:33

27 Sep 2022, 21:58

Thanks, it solved myy doubts

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest