Grid column visibility binding causes exception - Cannot convert undefined or null to object

When using the grid column visibility binding :

 <e-column [visible]="showRankingColumn" field="ranking" headerText="Ranking"><e-column>

An exception is raised if this binding value changes after the initial render and the column is using a template.

if (Object.keys(curChild.properties).length !== 0)

https://github.com/syncfusion/ej2-angular-ui-components/commit/00c932a8b4e1a35cbc3994759ace8991c21a2cdf#r48826187

Where curChild.properties is undefined.

See detailed replication:


I believe this is a regression as this functionality previously worked.

6 Replies 1 reply marked as answer

RR Rajapandi Ravi Syncfusion Team March 31, 2021 02:02 PM UTC

Hi Jeremy, 

Greetings from syncfusion support 

We have analyzed your query and we found that you are defining async function in ngOnInit. By validating this scenario, we found that defining async in ngOnInit is not the correct way and it causes some issues. From validating your query, we could see that you like to change the Boolean variable as true in the initial rendering and update the column visible property as true.  

So, you can achieve your requirement by using load event of Grid. Please refer the below code example and sample for more information. 


load() { //load event of Grid 
    (this.showRankingColumn as any) = true; 
    (this.showLocationColumn as any) = true; 
    console.log("Ranking Column Visible", this.showRankingColumn); 
    console.log("Location Column Visible", this.showLocationColumn); 
  } 





If it does not meet your requirement, please share the below details that will be helpful for us to provide better solution. 

1)      Please share us your exact requirement scenario with detailed description. 

2)      Please share the reason about why you are defining the async function in ngonInit. 

Regards, 
Rajapandi R 



JC Jeremy Carter March 31, 2021 09:14 PM UTC

Version v18.4.49 broke the usage of async ngOnInit. Currently using v18.4.46 and everything works correctly.


I can modify the code to not use async on the ngOnInit, but it is allowable syntax so I assumed it should work.


RR Rajapandi Ravi Syncfusion Team April 5, 2021 10:07 AM UTC

Hi Jeremy, 

We have analyzed your query and we could see that you are using v18.4.46 and it works correctly at your end. We have checked your shared stackblitz sample with the v18.4.46 but we are able to reproduce the same script error with this v18.4.46. Please refer the below sample for more information. 


Before we start providing solution on your query, we need some information for our clarification. So please share the below details that would be helpful for us to provide better solution. 

1)     Please share us your working sample with the v18.4.46. 

Regards, 
Rajapandi R


JC Jeremy Carter April 5, 2021 09:42 PM UTC

In your example you can clearly see the exception occurring.




JC Jeremy Carter April 5, 2021 10:11 PM UTC

I am happy with the solution to remove my async ngOnInit method in favor of rxjs.


RR Rajapandi Ravi Syncfusion Team April 6, 2021 08:40 AM UTC

Hi Jeremy, 

Based on your query we modified the sample and achieved your requirement by using rxjs. We suggest you use the below way to achieve your requirement. Please refer the below code example and sample for more information. 

 
ngOnInit() { 
    Observable.defer(async () => { 
      (this as any).showRankingColumn = await this.promiseDelay(true, 500); 
      (this as any).showLocationColumn = await this.promiseDelay(true, 500); 
    }).subscribe(x => { 
      setTimeout(() => { 
        var grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0]; 
        grid.refreshColumns(); //call refresh columns for UI changes 
      }); 
       
    } 
    ); 
  } 
 


Screenshot: 

 

Regards,
Rajapandi R 


Marked as answer
Loader.
Up arrow icon