简体   繁体   English

无论如何都没有打印任何完全适合A4纸的ag-grid尺寸吗?

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

I have a big ag-grid looks like below我有一个很大的 ag-grid 如下所示

在此处输入图像描述

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不知何故,我应该得到 PDF 导出并能够打印(均为 A4 纸尺寸)。我已经查看了 AG-Grid 文档以找到有用的东西在这里我想出了下面

 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这两种方法可以改变网格大小以打印所需的格式。但我不能让我的网格对角线更小以适合纸张大小。它只是裁剪我的网格的右侧,所以看起来像这样在此处输入图像描述

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.不管它有多小,只是我想把它完全放在 A4 纸上(垂直)。难道没有办法做到这一点吗?我也在考虑制作一个简单的 HTML 表格版本,没有边距和填充以适应纸,但那将是太多的工作,所以寻找更好和更简单的方法,如果存在的话。

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

Use the sizeColumnsToFit function on the grid API to fit all the columns within the grid, then print.使用网格sizeColumnsToFit上的 sizeColumnsToFit function 以适应网格内的所有列,然后打印。

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

Demo .演示

agGrid rows have a high line-height value in their css so they don't actually go back to line automatically. agGrid 行在其 css 中具有较高的行高值,因此它们实际上不会自动返回到行的 go 中。 which would result in a lot of ellipses and a harder table to read and print in your case.在您的情况下,这将导致很多省略号和更难阅读和打印的表格。

In the time of printing (If you don't need it somewhere else) you can add class to all cells via the defaultColDef that would force the cells to take at least 2 lines of data.在打印时(如果您在其他地方不需要它),您可以通过defaultColDef将 class 添加到所有单元格,这将强制单元格至少获取 2 行数据。 this way you can make the columns less wide.这样,您可以使列不那么宽。

defaultColDef: {
        ....

        cellClass: 'cell-wrap-text',
       
        ....
}
.cell-wrap-text{
  white-space: normal !important;
  line-height: 23px !important;
}

using that and with the sizeColumnsToFit() and setDomLayout('print') methods would give you a better result.使用它并使用 sizeColumnsToFit( sizeColumnsToFit()setDomLayout('print')方法会给你一个更好的结果。

Also if you are not using infinite mode on agGrid you can easily set the row height to something fixed or do that programmatically via the API (based on the text content inside the cells for that row).此外,如果您没有在 agGrid 上使用无限模式,您可以轻松地将行高设置为固定值,或者通过 API 以编程方式执行此操作(基于该行单元格内的文本内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM