简体   繁体   English

重新调整 Ag-Grid 的大小以适应行数

[英]Re-Size Ag-Grid to fit the number of rows

I am using Ag-Grid in an angular 8 application.我在 angular 8 应用程序中使用 Ag-Grid。 I am trying to get the grid to re-size based on the number of rows but also want to restrict the number of rows in the grid to 10 and then use pagination to display the next page.我试图让网格根据行数调整大小,但也想将网格中的行数限制为 10,然后使用分页显示下一页。

To restrict the number of rows in the grid to 10 I am using gridHeight = '400px' which works fine for the pages which have 10 rows.为了将网格中的行数限制为 10,我使用的是 gridHeight = '400px',它适用于具有 10 行的页面。 But lets say I have 33 rows of data and I display 10 rows each on the first 3 pages and the remaining 3 rows on the last page, the last page still have a gridHeight of 400px.但是假设我有 33 行数据,前 3 页各显示 10 行,最后一页显示其余 3 行,最后一页的 gridHeight 仍然为 400px。 Is there a way to make this dynamic so that the grid re-sizes for the 3 rows.有没有办法让它变得动态,以便网格重新调整 3 行的大小。

I know we can use domLayout='autoHeight' but that does not work with gridHeight.我知道我们可以使用 domLayout='autoHeight' 但这不适用于 gridHeight。 Any suggestions?有什么建议么?

instead of using gridHeight = '400px' to restrict the number of rows in the grid to 10 you should use paginationPageSize property and set it to 10.不要使用gridHeight = '400px'将网格中的行数限制为 10,而应使用paginationPageSize属性并将其设置为 10。

And like you mentioned while defining your grid options define domLayout property to 'autoHeight'.就像您在定义网格选项时提到的那样,将domLayout属性定义为“autoHeight”。 this will auto adjust grid height whenever there are lesser number of records in the grid.只要网格中的记录数量较少,这将自动调整网格高度。

here is some code snippet to help you out.这里有一些代码片段可以帮助你。

  var gridOptions - {
  defaultColdDef : {
  ...
  ...
  },
  --bunch of properties goes here 
  ...
  pagination : true,
  //use pagination page size property to set height instead of using height style.
  paginationPageSize : 10,
  domLayout : 'autoHeight'
  ...
  ...
  }

and here is a working demo这是一个工作演示

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

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