Skip to content

Commit

Permalink
Handle issues arrising from objects in data structure by throwing error
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielliwerant committed Sep 12, 2019
1 parent 8f91dac commit e63cf6d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,18 @@ class MUIDataTable extends React.Component {
};

transformData = (columns, data) => {
const leaf = (obj, path) => path.split('.').reduce((value, el) => (value ? value[el] : undefined), obj);
const leaf = (obj, path) => path.split('.').reduce((value, el) => {
if (typeof value[el] === 'object') throw Error(`Cannot accept objects for cell data from field "${el}". 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 value ? value[el] : undefined;
}, obj);

return Array.isArray(data[0])
? data.map(row => {
let i = -1;

return columns.map(col => {
if (!col.empty) i++;
if (typeof row[i] === 'object') 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 col.empty ? undefined : row[i];
});
})
Expand Down

0 comments on commit e63cf6d

Please sign in to comment.