onExportReady
Capture the export function through onExportReady, configure CSV, XLSX, or PDF output, and call it to obtain the exported file.
The onExportReady callback hands you an export function (IExportFunction) that exports the data of a rendered visualization into CSV, XLSX, or PDF. The function accepts one parameter, the exportConfig object (IExtendedExportConfig), and resolves to an IExportResult that describes the exported file.
The onExportReady callback is available on all visualization components, including InsightView.
Structure
import { InsightView } from "@gooddata/sdk-ui-ext";
<InsightView
insight="<visualization-id>"
onExportReady={(exportFunction) => {
/* hold onto the function and call it to export as needed */
}}
/>;
exportConfig
The exportConfig object includes the following properties:
format(optional, string) specifies the format of the exported data. Can be set tocsv(default),xlsx,raw, orpdf.title(optional, string) becomes the file name of the export. When you omit it,InsightViewuses the title of the saved visualization; other components use theirexportTitleprop, thenUntitled. Characters that aren’t allowed in file names are stripped.delimiter(only whenformatiscsv; optional, string) is the field delimiter.showFilters(only whenformatisxlsxorpdf; optional, boolean) specifies whether the applied filters are included in the export as human-readable context (true) or not (false; default). For PDF, this requiresvisualizationObjectId.includeFilterContext(optional, boolean) is an alias ofshowFilters; setting either totrueincludes the filters.mergeHeaders(only whenformatisxlsx; optional, boolean) specifies whether repeating header cells are merged (true) or not (false; default).pdfConfiguration(only whenformatispdf; optional,IExportPdfConfig) setspageSize(A3,A4, orLETTER),pageOrientation(PORTRAITorLANDSCAPE), andshowInfoPage.visualizationObjectId(only whenformatispdf; optional, string) exports the saved visualization with this identifier instead of the component’s execution result.visualizationObjectCustomFilters(only withvisualizationObjectId; optional,IFilter[]) applies these filters to the exported visualization object without changing the one being displayed.grandTotalsPosition(optional,pinnedTop,pinnedBottom,top, orbottom) sets where grand totals appear in the export and takes precedence over the position stored in the visualization object.timeout(optional, number) overrides the default polling timeout for the export result, in milliseconds. Don’t set it below 5000; a shorter timeout allows only one polling attempt.
Export result
The export function resolves to an IExportResult object:
uri(string) is the API URI from which you can fetch the exported file again.objectUrl(string) is a browser object URL pointing at the downloaded file in memory. Use it to offer an immediate download without another network round-trip, and callURL.revokeObjectURL()when you no longer need it to release the memory.fileName(optional, string) is the file name provided by the export service.
Example
import { useRef } from "react";
import { type IExportFunction } from "@gooddata/sdk-ui";
import { InsightView } from "@gooddata/sdk-ui-ext";
export function Example() {
const exportFunctionRef = useRef<IExportFunction | null>(null);
const onExportReady = (exportFunction: IExportFunction) => {
exportFunctionRef.current = exportFunction;
};
const doExport = async () => {
if (!exportFunctionRef.current) {
return; // the visualization has not loaded yet
}
try {
const result = await exportFunctionRef.current({
format: "xlsx",
showFilters: true,
mergeHeaders: true,
title: "CustomTitle",
});
console.log("Export succeeded: ", result.uri);
} catch (error) {
console.log("Export error: ", error);
}
};
return (
<div style={{ height: 367 }}>
<InsightView insight="<visualization-id>" onExportReady={onExportReady} />
<button className="button button-secondary" onClick={doExport}>
Export
</button>
</div>
);
}
Notes
- The callback fires each time the component finishes loading data. If the execution fails, the export function it receives rejects with the same
GoodDataSdkError. - The
Kpicomponent doesn’t support export. onExportReadyis for exporting a visualization component you render yourself, such as a standaloneInsightView. If you’re building a dashboard plugin that replaces a widget’s visualization renderer, forwardpushDatainstead so the Dashboard component’s own Export popup can offer CSV and XLSX for that widget — see Enable CSV and XLSX export for custom visualization renderers.
Related
Use useDataExport to run CSV, XLSX, or raw exports from a prepared execution, handle export lifecycle callbacks, and retrieve the download URI.
Trigger a whole-dashboard export to PDF, PPTX, or tabular format, make custom widgets export-ready, and customize how a dashboard decomposes into export slides.
Shared behavior of GoodData.UI visual components — responsive sizing, the style and data props model, and the visualization lifecycle callbacks.
Render any saved GoodData visualization by reference with the InsightView component.