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

Null Checks for OrganizationChart #3758

Closed
DeniseCP opened this issue Aug 25, 2017 · 4 comments
Closed

Null Checks for OrganizationChart #3758

DeniseCP opened this issue Aug 25, 2017 · 4 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@DeniseCP
Copy link

DeniseCP commented Aug 25, 2017

There is no guarantee in receiving a response in GitHub Issue Tracker, If you'd like to secure our response, you may consider PrimeNG PRO Support where support is provided within 4 business hours

I'm submitting a ... (check one with "x")

[ ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ x ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior

ERROR TypeError: Cannot read property 'styleClass' of null
    at Object.View_OrganizationChartNode_0._co [as updateDirectives] (OrganizationChartNode.html:4)
    at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:13058)
    at checkAndUpdateView (core.es5.js:12238)
    at callViewAction (core.es5.js:12603)
    at execComponentViewsAction (core.es5.js:12535)
    at checkAndUpdateView (core.es5.js:12244)
    at callViewAction (core.es5.js:12603)
    at execComponentViewsAction (core.es5.js:12535)
    at checkAndUpdateView (core.es5.js:12244)
    at callViewAction (core.es5.js:12603)

I have a service that returns an json. Once with that data I call a recursive function to build my org chart, the org chart shows on the screen but I get this error always, and I don't know where to look for solutions, since I'm using the ngOnInit as the example showed to add data to the org chart.

public chart: TreeNode[];
  superGroupCounter = 0;  
  groupsArray = [];

  constructor(private recordsService: RecordsService) { }

  ngOnInit() {
    this.recordsService.getGroupsJSON()
      .subscribe(res => {
        this.data = res
        this.recursive(this.data) 
        this.chart = this.groupsArray       
      })     
  }  

  recursive (obj, root?){
    var count = 0
    var superGroup = null
    var parent = 0
    for (var k in obj)
      {
        if (typeof obj[k] == "object" && obj[k] !== null) {
          if (k==="groups") { //It's a branch
            this.superGroupCounter++
            superGroup = "Group " + this.superGroupCounter
              for(let index = 0; index < obj[k].length; index++){                         
                if(obj[k][index].hasOwnProperty("groups")){
                  root['children'].push (
                    {
                      "label" : superGroup,
                      "expanded": true,
                      "data" : obj[k][index].weight ,
                      "leaf" : false,
                      "styleClass": 'ui-person'
                    })
                  this.recursive(obj[k][index], root["children"][count])
                }else {
                  if(!root['children']) {
                    root['children'] = []
                  }
                  root['children'].push (
                    {
                      "label" : obj[k][index].name,
                      "data" : obj[k][index].name ,
                      "leaf" : true,
                      "styleClass": 'ui-person'
                    })
                  count++
                }
              }                        
            }
          } else {
            if(k === 'total'){
              this.groupsArray.push(                  
                {
                  "label" : obj[k],
                  "expanded": true,
                  "data" :  obj[k].weight ,
                  "leaf" : false,
                  "type": 'root',
                  "styleClass": 'ui-person'
                })
              root = this.groupsArray[parent]
            }            
          this.recursive(obj[k], root) 
        }                  
      }
    }

Please tell us about your environment:
Windows 10, Chrome 59+, VSCode, Node 5.3.0

@cagataycivici cagataycivici self-assigned this Aug 25, 2017
@cagataycivici cagataycivici added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Aug 25, 2017
@cagataycivici cagataycivici added this to the 4.1.4 milestone Aug 25, 2017
@cagataycivici
Copy link
Member

Got your twitter message, will review tomorrow 🙂

@cagataycivici
Copy link
Member

Unable to replicate, please provide a case at;

http://plnkr.co/edit/Qi2Nw2imLpDUF8NJinYw?p=preview

@cagataycivici cagataycivici removed this from the 4.1.4 milestone Aug 27, 2017
@cagataycivici cagataycivici changed the title OrganizationChartNode Cannot read property 'styleClass' of null Null Checks for OrganizationChart Aug 27, 2017
@cagataycivici cagataycivici added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Aug 27, 2017
@cagataycivici cagataycivici added this to the 4.1.4 milestone Aug 27, 2017
@cagataycivici
Copy link
Member

Anyway, I've added some null checks via ngIf which I believe should fix this, try with monday's 4.2.RC1 please.

@DeniseCP
Copy link
Author

Thanks @cagataycivici it worked! No more console errors! I owe you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

2 participants