Skip to content

CSV export ​

exportable adds an Export CSV button above the table. exportFileName sets the name of the downloaded file, without the extension.

vue
<template>
  <VTable ref="table" :columns="columns" :data="products" exportable exportFileName="products" clientSide :itemsPerPage="5" />
  <p class="demo-log">
    <button type="button" @click="table?.exportCsv('my-file')">Export from my own button</button>
  </p>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { VTable, type Column } from "v-table-system";
import { products } from "./data";

const table = ref<InstanceType<typeof VTable>>();

const columns: Column[] = [
  { key: "id", label: "ID" },
  { key: "name", label: "Name" },
  { key: "price", label: "Price", format: (value) => `$${value}` },
];
</script>

What ends up in the file ​

  • The visible columns, with their labels as the first line. The actions column is skipped.
  • Values go through the column's format function. html and slots are not used, the raw value is written instead.
  • With clientSide: every row that matches the current search, in the current sort order, not only the current page.
  • Without clientSide: the rows currently in data, which is the current page.

The file is UTF-8 with a byte order mark, so Excel opens Arabic and other non-Latin text correctly.

Your own button ​

Call exportCsv(fileName?) on the component to start the download from anywhere. Change the label of the built-in button with the texts prop.

Released under the Apache-2.0 License.