Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle issues arising from objects in data structure by throwing error #921

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,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;

Expand All @@ -453,6 +453,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 = () => {}) {
Expand Down