/utils/csvDownload
The csvDownload module exports a default method to turn an array into a comma separated text file.
- Source
Methods
(inner) csvDownload(data, paramsopt)
The function turns an array of records into a text blob. The blob is transfomed to an ObjectURL which can be referenced in an anchor [link] tag. The hidden tag element is appended to the document.body and programmatically clicked to download the ObjectURL as a text file.
Name | Type | Attributes | Description |
---|---|---|---|
data | array | An array of records for the csv text file. | |
params | Object | <optional> | The parameters object. |
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
params.separator | String | <optional> | ',' | The seperator used in the csv text file. |
params.type | String | <optional> | 'text/csv;charset=utf-8;' | The type for the csv text file includes the charset required for character support. |
params.join | String | <optional> | '\r\n' | The characters used to join the row strings. The default being [carriage] return \r and [new] line feed \n. |
params.file | String | <optional> | 'file' | The file name for the download generated from clicking the ObjectURL link. |
params.header | Boolean | <optional> | Whether a header should be added to the CSV file. | |
params.fields | Array | <optional> | An array of field objects for the fieldsFunction and header row. |
- Source
(inner) fieldsFunction(record, fields) → {Array}
The fieldsFunction method receives a record obect and the fields array param. The method iterated through the fields array and formats the record [field] property according the fields params object.
Name | Type | Description |
---|---|---|
record | Object | A record object represents the data for a CSV row. |
fields | Array | An array of field params objects. |
- Source
Returns an array of field string values to be merged joined as a CSV row.
- Type:
- Array