DataTable dynamic column exporting

UI Components for Vue
Post Reply
mariusurbelis
Posts: 2
Joined: 26 Aug 2023, 11:52

26 Aug 2023, 12:06

Hi!

I am using PrimeVue DataTable and I want to export the table using exportCSV(). However, the table has some dynamic columns.

The column looks like this:

Code: Select all

<Column
            v-for="col of checkColumns"
            :key="col.id"
            :field="col.id"
            :header="col.header"
            :exportHeader="col.header"
            :exportable="true"
>
            <template #body="{ data }">
                {{ data?.data[col.id]?.data }}
            </template>
</Column>
For other columns that have templates with custom formatted data I have gotten away with using :exportFunction="beforeExportFunction" on the DataTable. In the beforeExportFunction I would do the custom data formatting depending on the field name like this:

Code: Select all

beforeExportFunction({ data, field }) {
    if (field == "form_id") {
        return this.getByID(this.checkForms, data)?.title;
    } else if (field == "date") {
        return this.printTimeLong(data);
    } else if (field == "created_by") {
        return (
            this.getByID(this.users, data)?.first_name +
            " " +
            this.getByID(this.users, data)?.last_name
        );
    } else {
        return data;
    }
}
But with custom columns they do not seem to be calling the beforeExportFunction thus I cannot get their data custom formatted.

Is there something I am missing? Thanks

tugce.kucukoglu
Posts: 560
Joined: 23 Oct 2020, 09:28

28 Aug 2023, 14:18

Can not replicate the issue. Do you have a codesandbox link?

mariusurbelis
Posts: 2
Joined: 26 Aug 2023, 11:52

28 Aug 2023, 15:05

Here is a minimum viable reproduction of the issue: https://codesandbox.io/s/polished-sun-2 ... ue:695-717

If I remove line 33 in Table.vue which is :field="col.id" from the code, then the error stops being displayed but the columns are not exported into the CSV.

My actual program of similar nature (not in CodeSandbox) exports the columns to the CSV but those columns are empty.

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests