Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

javascript - Isn't there anyway to print any ag-grid size compeletely fit into A4 paper?

I have a big ag-grid looks like below

enter image description here

Somehow I should get PDF export of this and being able to print (both A4 paper size).I've reviewed AG-Grid documentation to find something useful here what I came up with below

 onBtPrinterFriendly() {
    var eGridDiv = document.querySelector('#myGrid');
    eGridDiv.style.width = '';
    eGridDiv.style.height = '';
    this.gridApi.setDomLayout('print');
    print();
  }
  onBtNormal() {
    var eGridDiv = document.querySelector('#myGrid');
    eGridDiv.style.width = '400px';
    eGridDiv.style.height = '200px';
    this.gridApi.setDomLayout(null);
  }

These two methods can change grid size to print on desired format.But I can't make my grid smaller diagonally to fit paper size.It justs crops the right side of my grid so looks like this enter image description here

Doesn't matter how small that would be ,just I wanna put it compeletely A4 paper(vertically).Isn't there anyway to achieve this?I'm also thinking about making a simple HTML table versiton without margins and paddings to fit into paper but that would be too much work so looking for better and easier way if exists.

Plunker example: https://plnkr.co/edit/rVPswsaknukOkhf5

question from:https://stackoverflow.com/questions/66045279/isnt-there-anyway-to-print-any-ag-grid-size-compeletely-fit-into-a4-paper

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the sizeColumnsToFit function on the grid API to fit all the columns within the grid, then print.

onBtPrinterFriendly() {
    var eGridDiv = document.querySelector('#myGrid');
    eGridDiv.style.width = '';
    eGridDiv.style.height = '';
    this.gridApi.sizeColumnsToFit();
    this.gridApi.setDomLayout('print');
    print();
  }

Demo.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...