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

DataTable crashes with a "Cannot read property 'xxx' of undefined" for nested objects #791

Closed
HOTwheel opened this issue Feb 28, 2019 · 0 comments
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@HOTwheel
Copy link

HOTwheel commented Feb 28, 2019

[X] bug report
[ ] feature request
[ ] support request

The following issue has already been reported and fixed for PrimeNG, same root cause:
primefaces/primeng#1451

Current behavior
DataTable does crash if parent of referenced field in column-definition is not defined.

<Column
     field={'example.person.firstName'}
/>

If object 'person' is undefined, the following error occurs and the page does not get rendered.

Uncaught TypeError: Cannot read property "firstName" of undefined
    at Function.resolveFieldData (ObjectUtils.js:133)
    at BodyCell.render (BodyCell.js:313)
    at finishClassComponent (react-dom.development.js:14979)
    at updateClassComponent (react-dom.development.js:14934)
    at beginWork (react-dom.development.js:15840)
...

Occurs in function resolveFieldData of ObjectUtils.js in the following loop:

for (var i = 0, len = fields.length; i < len; ++i) {
            value = value[fields[i]];
          }

Expected behavior
DataTable should not crash in case the field can not be resolved, just skip/leave the field empty.

Minimal reproduction of the problem with instructions
Define a nested field in colum definition whose parent is undefined/null in at least one object of the table dataset.

  • React version:
    16.8.1

  • PrimeReact version:
    3.1.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
    all

  • Language: [all | TypeScript X.X | ES6/7 | ES5]
    ES6

@mertsincan mertsincan self-assigned this Feb 28, 2019
@mertsincan mertsincan added the Type: Bug Issue contains a defect related to a specific component. label Feb 28, 2019
@mertsincan mertsincan added this to the 3.1.1 milestone Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

2 participants