If the built-in column types are not enough, you can define your own data structure using the String column. You do this through the use of onValidateRecord
. You simply need to validate that the value passed to onValidateRecord
matches your desired format.
Example of Creating a “Currency” Column
const currencyRegex = /\$[0-9]*/;
const importer = new FuseImporter();
importer.getSessionToken = ...
importer.addColumn({
internal_key: "total_charge",
label: "Total Charge",
column_type: "string",
required: true,
position: 1,
unique: true,
});
importer.onValidateRecord = async (record) => {
const errors = {};
const warnings = {};
if (!record.total_charge?.match(currencyRegex)) {
errors["total_charge"] =
"Total charge must be a dollar amount matching the format $xx";
}
return {
errors: errors,
warnings: warnings,
};
};
importer.show();