AdaptTable for Element Plus

CSV export in Element Plus

Compose exportCsv() and an export button joins the toolbar. It writes the page on screen as it stands — sorted, filtered and searched — to a CSV file the browser downloads.

A column's exportValue decides what the file gets, so a cell that shows a formatted date range exports the plain start date a spreadsheet sorts.

The code

<script setup lang="ts">
import type { ColumnDef } from "@adapttable/vue";
import { DataTable } from "@adapttable/element-plus";
import { exportCsv } from "@adapttable/element-plus/export";

defineProps<{ rows: readonly Person[] }>();

const columns: ColumnDef<Person>[] = [
  { key: "name", sortable: true },
  { key: "team" },
  { key: "budget", sortable: true },
];
const rowKey = (row: Person) => row.id;
const features = [exportCsv()];
</script>

<template>
  <DataTable
    :data="rows"
    :columns="columns"
    :row-key="rowKey"
    :features="features"
  />
</template>

Install

pnpm add @adapttable/element-plus @adapttable/vue @adapttable/core element-plus

The same feature in the other kits

More Element Plus features

Reference: exporting, export-pdf. More of this kit: AdaptTable for Element Plus, or the live demo.