Dynamic Columns
Add new columns to the template at run-time.
Last updated
Add new columns to the template at run-time.
Last updated
Consider a scenario where you cannot have a fixed template for collecting data. The columns in the data model depend on the end user's preferences and/or some other criteria.
For such cases, csvbox provides the flexibility to add unique dynamic columns for each import at run-time.
You can configure dynamic columns via the installation code.
Here's a basic configuration that adds 2 dynamic columns qualification and experience.
Pass the dynamic columns that you want to add as an array input parameter to thesetDynamicColumns()
method while initializing the importer.
Basic installation steps are available here.
Dynamic columns will be visible in the importer along with the other regular columns.
Dynamic columns can be configured by passing additional<key>: <value>
pairs to the array input parameter of thesetDynamicColumns()
method.
Here is an example illustrating more configuration options.
column_name is the only key that is mandatory for adding a dynamic column.
It is the column name that will be pushed to the data destination.
The user-friendly column label that the users will see in the importer.
Info Hints are help tooltips that will get displayed when the users hover the mouse over the Display Label (or click it) in the importer.
Comma-separated set of keywords as alternative matching options to help users match column names automatically.
It specifies the data type of the incoming data. Possible values are: text, number, email, date, boolean, regex, ip, url, credit_card, phone_number, currency, list, dependent_list, dynamic_list, dependent_dynamic_list, multiselect_list, and multiselect_dynamic_list.
The validation rules for the data based on the column type. Validator options are mentioned below.
A default filler value for the column in case the incoming data is blank.
It indicates whether a column is mandatory.
It defines the display index of the column. Starts from 1.
If configured to true then the users will not be able to edit the data of this column. The default value is false.
text
min_length
max_length
"min_length": 2,
"max_length": 50
number
min_value
max_value
number_type - Valid values: "any", "integer" - Default: "any"
allow_commas - Valid values: true, false - Default: false
"min_value": -2,
"max_value": 100, "number_type": "integer", "allow_commas": true
-
date
format
"format": ["MM/DD/YYYY", "MM.DD.YYYY", "MM-DD-YYYY"]
boolean
-
regex
expression
"expression": "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"
Note: The special characters in the expression need to be escaped. You may use a tool like this for escaping.
ip
version
"version": “ipv4”
url
-
credit_card
-
phone_number
country_code
"country_code": "de"
currency
symbol
require_symbol
allow_space_after_symbol
symbol_after_digits
allow_negatives
parens_for_negatives
negative_sign_before_digits
negative_sign_after_digits
thousands_separato
decimal_separator
allow_decimal
require_decimal
digits_after_decima
allow_space_after_digits
Note: The array digits_after_decimal
is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3].
"symbol": "$",
"require_symbol": false,
"allow_space_after_symbol": false, "symbol_after_digits": false, "allow_negatives": true, "parens_for_negatives": false, "negative_sign_before_digits": false,
"negative_sign_after_digits": false,
"thousands_separator": ",", "decimal_separator": ".", "allow_decimal": true, "require_decimal": false, "digits_after_decimal": 2, "allow_space_after_digits": false
list
values
value
display_label (optional)
dependents (optional)
value
display_label
case_sensitive
other_values (Optional. Default is false)
accept_list_values (Optional. Default is false)
"values": [
{"value": "USA", "display_label": "USA", "dependents": [ {"value": "ny", "display_label": "New York"}, {"value": "ch", "display_label": "Chicago"}, {"value": "se", "display_label": "Seatle"}, {"value": "mi", "display_label": "Miami"} ]}, {"value": "Canada", "display_label": "Canada", "dependents": [ {"value": "to", "display_label": "Toronto"}, {"value": "va", "display_label": "Vancouver"} ]}
],
"case_sensitive": false, "other_values": false, "accept_list_values": true
dependent_list
primary_column
"primary_column": "countries"
dynamic_list
source_url
request_method
request_headers
custom_user_attributes (Optional. Default is true)
other_values (Optional. Default is false)
"source_url": "https://api.myapp.com/countries", "request_method": "POST",
"request_headers": [
{"key": "Content-Type", "value": "application/json"},
{"key": "X-Access-Token", "value": "71ab1d73a4d1319b260e9a0sdbdbc1c"}
], custom_user_attributes: true, "other_values": false
dependent_dynamic_list
primary_column
"primary_column": "countries"
multiselect_list
values
delimiter (Optional. Default is comma ",")
case_sensitive
other_values (Optional. Default is false)
"values": ["Red", "Green", "Blue"],
"delimiter": ".", "case_sensitive": false, "other_values": false
multiselect_dynamic_list
source_url
request_method
request_headers
delimiter (Optional. Default is comma ",")
other_values (Optional. Default is false)
"source_url": "https://api.myapp.com/colors", "request_method": "POST",
"request_headers": [
{"key": "Content-Type", "value": "application/json"},
{"key": "X-Access-Token", "value": "71ab1d73a4d1319b260e9a0sdbdbc1c"}
], "delimiter": ".", "other_values": false
In general, the dynamic columns are displayed only after the regular columns.
The position
parameter helps to re-order the position of the dynamic columns and get them displayed before or in between the regular columns.
The position
value starts from 1 indicating the first position in the final column list. It is an optional parameter while defining the dynamic columns.
The data from the dynamic columns is available in the data destinations along with the data from the regular columns. Currently, dynamic columns are supported by the following destinations only:
In the API response JSON object, the dynamic data will be displayed inside the _dynamic_data object as shown below. The _dynamic_data object will be visible only if the dynamic columns are configured for the import. In the example below check lines 12 and 31.
In the AWS S3 file store, the dynamic columns will be added as new columns in the uploaded file.