0

Referred example from Printing section of ag-grid documentation (https://www.ag-grid.com/javascript-grid-for-print/). This is the snippet from typescript file .

         onBtPrint(){
              var gridApi = this.gridApi;
              this.setPrinterFriendly(gridApi);
                setTimeout(function() {
                print();
                this.setNormal(gridApi);
              }, 2000);
            }
            setPrinterFriendly(gridApi) {
              var eGridDiv = document.querySelector(".my-grid");
              (eGridDiv as HTMLElement).style.width = "";
              (eGridDiv as HTMLElement).style.height = "";
              this.gridApi.setDomLayout("print");
            }
            setNormal(gridApi) {
              var eGridDiv = document.querySelector(".my-grid");
              (eGridDiv as HTMLElement).style.width = "600px";
              (eGridDiv as HTMLElement).style.height = "200px";
              this.gridApi.setDomLayout("print");
            }
    Below is my html template , on clicking print button i am trying 
   to call onBtPrint() 

      <button (click)="onBtPrint()">print</button> 
            <div class="bx--row" [ngStyle]="style">
              <div class="bx--col-md-12" >
              <ag-grid-angular #agGrid style="width: 100%; height: 600px;" class="ag-theme-balham my-grid" id="myGrid" 

                  [gridOptions]="gridOptions"
                  [columnDefs]="columnDefs"
                  [rowData]="rowData"
                  [defaultColDef]="defaultColDef"
                  [domLayout]="domLayout"
                  (gridReady)="onReady($event)" 
             </ag-grid-angular>
             <div>
             <input style= "opacity:0" readonly #modal>
            </div>
           </div>
  Which version of ag-grid should i use .
  • This information are not enough. Please share some more details what the angular version, ag-grid version and required code. – Jitendra G2 Jan 02 '19 at 06:01
  • I am using angular 6 , ag-grid version 18.1 , – Ila Baskaran Jan 02 '19 at 07:35
  • 1
    Stop using anonymous functions. use arrow functions. `setTimeout(() => { ... })` And define your setPrinterFriendly and setNormal functions as private methods of your component. – JB Nizet Jan 02 '19 at 08:59
  • Possible duplicate of [How to access the correct \`this\` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – JB Nizet Jan 02 '19 at 09:01
  • did the changes does'nt seem to work , in which version of ag-grid print is supported ? – Ila Baskaran Jan 02 '19 at 09:36

1 Answers1

1

Which your using ag-grid 18.1 api doesn't introduced setDomlayout property. So you just need to update ag-Grid to v20 for this functionality.

Roy
  • 880
  • 7
  • 21
  • 39