diff --git a/src/MUIDataTable.js b/src/MUIDataTable.js index 5aa94a5ef..c2daeb222 100644 --- a/src/MUIDataTable.js +++ b/src/MUIDataTable.js @@ -454,7 +454,7 @@ class MUIDataTable extends React.Component { transformData = (columns, data) => { const leaf = (obj, path) => path.split('.').reduce((value, el) => (value ? value[el] : undefined), obj); - return Array.isArray(data[0]) + const transformedData = Array.isArray(data[0]) ? data.map(row => { let i = -1; @@ -464,6 +464,12 @@ class MUIDataTable extends React.Component { }); }) : data.map(row => columns.map(col => leaf(row, col.name))); + + // We need to determine if object data exists in the transformed structure, as this is currently not allowed + const hasInvalidData = transformedData.filter(data => data.filter(d => typeof d === 'object' && d !== null && !Array.isArray(d)).length > 0).length > 0; + if (hasInvalidData) throw Error(`Cannot accept objects for cell data. Cells need to contain strings | numbers. It\'s possible this error is the result of a missing dot in the column name field (e.g. name: "company" instead of name: "company.id")`); + + return transformedData; }; setTableData(props, status, callback = () => {}) {