You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

to_csv()

Usage

to_csv(nodes, propertiesOrView[, delimiterChar = ';' [, quoteChar = '"' [, recordSeparator = "\n" [, includeHeader = true[, localizeHeader = false [, headerLocalizationDomain]]]])

Description
Returns a CSV string representation of the given collection of objects.

Parameters

  • nodes: A collection of objects (these objects can be database nodes or javascript objects)
  • propertiesOrView: The name of a view (e.g. ui or public) or a collection of property names (e.g. merge('id', 'name') in StructrScript or ['id', 'name'] in JavaScript)
    • If the nodes parameter was a collection of javascript objects this needs to be a collection of property names
    • If the nodes parameter was a collection of database nodes, a collection of property names or a view name can be used
  • delimiterChar (default: ;): A single character used as the column separator. (If more than one character is supplied, only the first character is used without raising an error)
  • quoteChar (default: "): A single character used as the quote character. (If more than one character is supplied, only the first character is used without raising an error)
  • recordSeparator (default: \n): The separator between the records (recommended usage is \n, \r or \r\n)
  • includeHeader (default true): Switch indicating if a header row should be printed
  • localizeHeader (default false): Switch indicating if the column names in the header should be localized
  • headerLocalizationDomain: Optional header localization domain

Note

  • If the column values contain the quote character, a \ is prepended before that instance of the quote character
  • All instances of \n or \r in the column values are replaced by \\n and \\r respectively so we can guarantee that only intended newlines (i.e. the record separator) occurr inside the produced CSV
  • The content of the header row depends on the contents of propertiesOrView and the localization configuration.
    • If a view is given, the (optionally localized) property names of that view are used as header row
    • If a collection of properties is given, these (optionally localized) property names are used as a header row

Example

${to_csv(find('User'), 'public')}
${to_csv(find('User'), merge('id', 'name'))}

results in

"id";"type";"name";"isUser"
"70fd9f831cad4506a1076f956ffa2a0b";"User";"admin";"true"

"id";"name"
"70fd9f831cad4506a1076f956ffa2a0b";"admin"

Search results for "to_csv()"

to_csv()

Returns a CSV string representation of the given collection of objects.

Parameter Description
nodes A collection of objects (these objects can be database nodes or javascript objects)
propertiesOrView The name of a view (e.g. ui or public) or a collection of property names (e.g. merge(‘id’, ‘name’) in StructrScript or [‘id’, ‘name’] in JavaScript). If the nodes parameter was a collection of javascript objects this needs to be a collection of property names. If the nodes parameter was a collection of database nodes, a collection of property names or a view name can be used.
delimiterChar A single character used as the column separator. (If more than one character is supplied, only the first character is used without raising an error) (default: ;)
quoteChar A single character used as the quote character. (If more than one character is supplied, only the first character is used without raising an error) (default (")
recordSeparator The separator between the records (recommended usage is \n, \r or \r\n) (default: \n)
includeHeader Switch indicating if a header row should be printed (default true)
localizeHeader Switch indicating if the column names in the header should be localized (default: false)
headerLocalizationDomain Optional header localization domain
to_csv(nodes, propertiesOrView[, delimiterChar = ';' [, quoteChar = '"' [, recordSeparator = "\n" [, includeHeader = true[, localizeHeader = false [, headerLocalizationDomain]]]])