Skip to main content

Overview

dataHandler

Use our dataHandler feature on top of our cleaning functions to solve complex and complicated import scenarios. Take advantage of the advanced data access directly after the upload or after the mapping to customize your importer suiting your requirements.

DescriptionThe dataHandler is a powerful tool that can be executed before the “Header Selection”- and/or “Review Entries”-step, providing access to the original data and its metadata as well as enabling you to add/remove columns and rows. It can be configured to run based on your needs.
With the dataHandler function, you can solve complex data manipulation scenarios, such as transposing data, merging and splitting columns, joining sheets, de-nesting data, and more. Unlike other cleaning functions that iterate through every entry, the dataHandler function works on the entire data at once, giving you complete control over input data.
In addition, with the dataHandler function, you can add, delete, and modify columns and rows in the data, providing even greater flexibility in data manipulation.
Whether you need to transform a single column or an entire dataset, the dataHandler function provides the flexibility and power required to do the job effectively and efficiently.
Run EventThe execution of this function can occur before the “Header Selection”- or before the “Review Entries”-step, or even both, depending on the configuration.
Parameterdata: The data parameter is a data structure that provides detailed information about the imported file(s). It includes attributes such as the file size, file name, and file extension, as well as the original data of the input. The data includes the following properties:
  • fileSize - The size of the file in mb.
  • fileExtension - The extension of the file.
  • fileName - The name of the file.
  • data - Original data of the file.
modifier: The modifier parameter is a function that enables modifiying the data by adding or deleting columns and rows. This function allows customization of the data per your requirements. The modifier function includes the following sub-functions:
  • addRow() - Adds a new row to the data.
  • deleteRow()- Deletes an existing row from the data.
  • addColumn() - Adds a new column to the data.
  • deleteColumn() - Deletes an existing column from the data.
By utilizing these sub-functions, you can manipulate the data in a granular manner to meet your specific use case.
SyntaxBelow are the parameters’ syntax and examples of how to use them:
index:Specifies the position in the data where the new row will be inserted. If you pass an integer value for the index, the new row will be added to that specific index. If no index is passed or the index is null, a new row will be created at the end of the data.
data:
In the headerStep function, the data parameter comprises an array of arrays, where each inner array represents a new row of values to be added.

In the reviewStep function, the data parameter is an array of objects where each key represents a column name, and the corresponding value denotes the data to be added to the new row.

It should be noted that the addRow() function allows for adding multiple rows of data to the dataset at once.
dataHandler: {{
headerStep: async (modifier, metaData) => {
modifier.addRow({
index: 0,
data: [["value 1", "value 2"]]
});
},
reviewStep: async (modifier, metaData) => {
modifier.addRow({
index: 0,
data: [{key: "value"}]
});
},
}},
Implementation ExampleIn the given example, the address column is filled by merging the street, city, and country columns. Subsequently, the street, city, and country columns are removed from the output schema.
<NuvoImporter
licenseKey="Your License Key"
settings={{
developerMode: true,
identifier: "product_data",
columns: [
{
key: "full_name",
label: "Full name",
columnType: "string",
},
{
key: "street",
label: "Street",
columnType: "string",
},
{
key: "city",
label: "City",
columnType: "string",
},
{
key: "country",
label: "Country",
columnType: "string",
},
{
key: "Address",
label: "Address",
columnType: "string",
},
],
}}
dataHandler={{
reviewStep: async (modifier, data) => {
const dataLength = data.length;
const newData = data;
for (let i = 0; i < dataLength; i++) {
const element = data[i];

if (!element.Address && element.street && element.city && element.country) {
newData[i].Address = `${element.street}, ${element.city}, ${element.country}`;
}
}

modifier.removeColumn("street");
modifier.removeColumn("city");
modifier.removeColumn("country");
return newData;
},
}}
/>

Use cases

Here, you can access a list of some use cases that can be solved with the dataHandler:

Use caseSandbox link
Transpose data view
Merge sheets based on a unique column view
Calculate the sum of the rows view
Nest similar rows view
De-nesting complex rows view
Accessing file's metadata view
Create Un-mappable Columns view