React Data Grid ExportFile

Description

The ExportFile plugin lets you export table data as a string, blob, or downloadable CSV file.

See the export file demo for examples.

Example

const hotRef = useRef(null);

...

<HotTable
  ref={hotRef}
  data={getData()}
/>

const hot = hotRef.current.hotInstance;
// access to exportFile plugin instance
const exportPlugin = hot.getPlugin('exportFile');

// export as a string
exportPlugin.exportAsString('csv');

// export as a blob object
exportPlugin.exportAsBlob('csv');

// export to downloadable file (named: MyFile.csv)
exportPlugin.downloadFile('csv', {filename: 'MyFile'});

// export as a string (with specified data range):
exportPlugin.exportAsString('csv', {
  exportHiddenRows: true,     // default false
  exportHiddenColumns: true,  // default false
  columnHeaders: true,        // default false
  rowHeaders: true,           // default false
  columnDelimiter: ';',       // default ','
  range: [1, 1, 6, 6]         // [startRow, endRow, startColumn, endColumn]
});

Members

ExportOptions

Source code (opens new window)

ExportFile.ExportOptions : object

Properties

Name Type Default Description
[exportHiddenRows] boolean false Include hidden rows in the exported file.
[exportHiddenColumns] boolean false Include hidden columns in the exported file.
[columnHeaders] boolean false Include column headers in the exported file.
[rowHeaders] boolean false Include row headers in the exported file.
[columnDelimiter] string "," Column delimiter.
[range] string "[]" Cell range that will be exported to file.

Methods

downloadFile

Source code (opens new window)

exportFile.downloadFile(format, options)

Exports table data as a downloadable file.

Param Type Description
format string Export format type eq. 'csv'.
options ExportOptions Export options.

exportAsBlob

Source code (opens new window)

exportFile.exportAsBlob(format, options) ⇒ Blob

Exports table data as a blob object.

Param Type Description
format string Export format type eq. 'csv'.
options ExportOptions Export options.

exportAsString

Source code (opens new window)

exportFile.exportAsString(format, options) ⇒ string

Exports table data as a string.

Param Type Description
format string Export format type eq. 'csv'.
options ExportOptions Export options.

isEnabled

Source code (opens new window)

exportFile.isEnabled() ⇒ boolean

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit hook and if it returns true then the ExportFile#enablePlugin method is called.

Last update: Nov 20, 2024