2
votes

I have implemented ag-Grid by using angular in my project successfully. Now trying to print ag-Grid data through following official ag-Grid doc https://www.ag-grid.com/javascript-grid-for-print/ .

I'm calling that print functionality method under onCellDoubleClicked() method. While double click a cell, ag-grid data print window should open. But I'm getting error like 'ERROR TypeError: l.setDomLayout is not a function'.

This is the way I've created method.

onCellDoubleClicked($event) { 
var gridApi = this.gridApi; 
this.setPrinterFriendly(gridApi); 
setTimeout(function() { 
print(); 
this.setNormal(gridApi); 
}, 2000); 
} 
setPrinterFriendly(api) { 
var eGridDiv = document.querySelector(".my-grid"); 
this.style.width = ""; 
this.style.height = ""; 
api.setDomLayout("print"); 
} 
setNormal(api) { 
var eGridDiv = document.querySelector(".my-grid"); 
this.style.width = "600px"; 
this.style.height = "200px"; 
api.setDomLayout(null); 
}

Any one having idea please let me know, Is any thing I did wrong or correct approach. Thanks in advance.

This is the error:

enter image description here

1
You are passing "gridApi" to "setPrinterFriendly()" & "setNormal()" functions... what happens if you don't pass anything to these functions and instead of api.setDomLayout("print");, you do this.gridApi.setDomLayout("print"); ? - Akber Iqbal
Thanks for your suggestion, Yeah I've changed like this but no use. Still getting same error like 'ERROR TypeError: this.gridApi.setDomLayout is not a function' - Roy
If you put up a minimal stackblitz, someone will surely help - Akber Iqbal
not sure if you solved the issue already, but please check your ag-grid version. Their document does not mention what version this setDomLayout API applies to, but it seems added after v19. - wctiger
@wctiger Yes problem got solved..yes you are correct which I was using v18, after upgrading to latest version problem got solved. - Roy

1 Answers

0
votes

Since you tried this.gridApi.setDomLayout and still get 'this.gridApi.setDomLayout is not a function error', I guess this.gridApi is undefined. So add this in your JavaScript file.

onGridReady(params) {
   this.gridApi = params.api;
}

And this attribute

(gridReady)="onGridReady($event)"

inside the <ag-grid-angular> tag