Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · DATA GRID PLUGINS

@dojo-ng/data-grid-export

CSV export for <dj-data-grid>.

Try it in the playground

@dojo-ng/data-grid-export · v0.1.1 · A plugin for <dj-data-grid>, not a custom element

npm install @dojo-ng/data-grid-export

The chrome button downloads the current (filtered, unpaginated) rows. Import toCsv/downloadCsv and pass the grid element to build your own button.

<dj-data-grid id="g"></dj-data-grid>
<script type="module">
  import "@dojo-ng/data-grid";
  import { exportPlugin, toCsv } from "@dojo-ng/data-grid-export";
  const g = document.getElementById("g");
  g.columns = [{ id: "name", header: "Name" }];
  g.data = [{ name: "Widget" }, { name: "Gadget" }];
  g.plugins = [exportPlugin({ filename: "inventory.csv" })];
  // or, from your own UI: console.log(toCsv(g));
</script>

What is exported

  • Raw cell values, not the formatted text, because formatting is presentation.
  • By default, the filtered rows on all pages. With all: true, every row, before filtering.
  • Internal columns whose id starts with __, such as the detail expander, are skipped.

Functions

downloadCsv

function downloadCsv(source: CsvSource, { filename, all }?: ExportOptions): void;

exportPlugin

function exportPlugin({ filename, all }?: ExportOptions): DataGridPlugin;

toCsv

function toCsv(source: CsvSource, { all }?: CsvOptions): string;

Types

CsvOptions

interface CsvOptions {
  all?: boolean;
}

CsvSource

type CsvSource = Table<Row> | DataGridContext | DjDataGrid;

ExportOptions

interface ExportOptions extends CsvOptions {
  filename?: string;
}