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 null" for nested objects #555

Closed
renathoaz opened this issue Oct 13, 2020 · 3 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@renathoaz
Copy link

Templating will solve it for display data, but for Global filter it also crashes if the nested object is null.

@renathoaz
Copy link
Author

renathoaz commented Oct 14, 2020

I found the same issue already solved on primereact, the problem is pretty the same
primefaces/primereact#791

The solution is simple, please update resolveField on ObjectUtils

resolveFieldData(data, field) {
        if(data && field) {
            if (this.isFunction(field)) {
                return field(data);
            }
            else if(field.indexOf('.') === -1) {
                return data[field];
            }
            else {
                let fields = field.split('.');
                let value = data;
                for(var i = 0, len = fields.length; i < len; ++i) {
                    if (value == null) {
                        return null;
                    }
                    value = value[fields[i]];
                }
                return value;
            }
        }
        else {
            return null;
        }
    }

@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Oct 22, 2020
@cagataycivici cagataycivici added this to the 3.0.1 milestone Oct 22, 2020
@renathoaz
Copy link
Author

Sorry for commenting in a closed issue, but any possibility of having this issue fixed on a v2 release ?
I still need to use primevue v2.

@cagataycivici
Copy link
Member

Sure -> #665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants