I have the following javascript that creates a columns object to pass to handsontable initialization:
const columns = columnDataTypes.map((dataType, index) => {
const columnConfig = {
readOnly: readonlyColumns[index] // Set readOnly based on readonlyColumns array
};
// Apply validation and type settings based on the data type
switch (dataType) {
case 'Text':
columnConfig.type = 'text';
break;
case 'Numeric':
columnConfig.type = 'text';
columnConfig.validator = (value, callback) => {
// Check for empty values and treat them as valid (you can decide how to handle this)
if (value === null || value === '') {
callback(true); // Allow empty values
} else {
callback(!isNaN(parseFloat(value)) && isFinite(value));
}
};
break;
case 'Date':
columnConfig.type = 'date';
columnConfig.dateFormat = 'YYYY-MM-DD'; // Specify the date format
columnConfig.correctFormat = true; // Ensure correct format is checked
columnConfig.validator = (value, callback) => {
// Validate if the date is in the correct format
const dateFormat = /^\d{4}-\d{2}-\d{2}$/; // YYYY-MM-DD format
callback(dateFormat.test(value));
};
break;
case 'Boolean':
columnConfig.type = 'checkbox'; // Display checkbox for Boolean values
break;
default:
columnConfig.type = 'text'; // Default case for unrecognized types
}
return columnConfig;
});
The code above works as expected although columnConfig.type = ‘text’; should be columnConfig.type = ‘numeric’;
The problem is, when i mark any of the columns as numeric the table throws:
Uncaught TypeError: Cannot read properties of undefined (reading ‘languages’)
and then for each subsequent button press:
handsontable.min.js:31 Uncaught TypeError: Cannot read properties of null (reading ‘startColumn’)
the actual code to initialize the table is:
const hot = new Handsontable(container, {
language: ‘en-US’,
data: rowData,
colHeaders: headers,
rowHeaders: true,
contextMenu: true,
columns: columns,
licenseKey: ‘non-commercial-and-evaluation’
});
Why am i getting this error? How does specifying a numeric column type throw random languages doesn’t exist errors? The stack trace makes no sense whatsoever