useExporter
Runs a backend export (GET <resource>/export/) and downloads the returned file in the browser.
The export list action already wires it up through
ExportButton. Use it directly when a custom control should
trigger the same backend export.
Signature
import {useExporter} from 'habarico';
const exporter = useExporter('eshop/product');
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
resource (required) | string | — | Resource in "service/resource" form; also names the fallback file (/ becomes _) |
Returns
(params: ExportParams) => Promise<void> — calls the export endpoint and triggers the download:
await exporter({format: 'csv', fields: ['name', 'price'], ids: [1, 2]});
ExportParams:
| Name | Type | Description |
|---|---|---|
format (required) | string | Export format, e.g. csv |
fields | string[] | Restricts and orders the exported columns |
ids | Identifier[] | Exports exactly these records |
filter | FiltersConfiguration | Exports everything matching this filter (the getList filter format) |
sort | SortPayload | Row order, serialized like getList's order_by |
Behaviour
- The file is downloaded under the name from the response's
Content-Dispositionheader (RFC 5987filename*included); without one it falls back to<resource>.<format>. - A
202 Acceptedresponse means the export exceeded the synchronous threshold and runs in the background — the hook only shows thera.notification.export_runninginfo notification.
caution
The backend must expose Content-Disposition to the browser (CORS Access-Control-Expose-Headers),
otherwise every download falls back to the generic <resource>.<format> name.
See also
- Data provider — the
exportmethod this hook wraps - Button provider — the
exportaction renderingExportButton - SchemaList — the list the export button sits on