简体   繁体   English

ag 网格表溢出屏幕

[英]ag-grid table spilling out of screen

I have an ag-grid table that changes its size dynamically based on some buttons.我有一个 ag-grid 表,它根据一些按钮动态地改变它的大小。 more or less columns will be added or removed from the table.将在表格中添加或删除更多或更少的列。 However, as the number of columns increases, the table would eventually spill out of the page, which cannot be seen.但是,随着列数的增加,表格最终会溢出页面,无法看到。 I have tried to apply horizontal scrolling but to no avail.我尝试应用水平滚动但无济于事。

This is my code:这是我的代码:

<div class="row text-center" style="justify-content: center;">
  <div>
    <ag-grid-angular
      style="font-size: 15px; width: 100%;"
      class="ag-theme-balham"
      [rowData]="data"
      [columnDefs][="columnDefs"
      [defaultColDef]="defaultColumnDefs"
      (gridready)="onGridReady($event)"
    </ag-grid-angular>
  </div>
</div>

Basically, I want either two of the followings:基本上,我想要以下两个:

  1. the width of the ag-grid table to be fixed and horizontal scrolling enabled要固定的 ag-grid 表格的宽度并启用水平滚动
  2. OR the width of the ag-grid table can grow depending on the number of columns.或者 ag-grid 表的宽度可以根据列数增加。 However, it should not spill out of the page.但是,它不应溢出页面。

And also, I would like the table to be centralized in the middle of the page as well.而且,我希望表格也集中在页面中间。 Thanks!谢谢!

You can try:你可以试试:

<ag-grid-angular
      style="font-size: 15px; width: 100%;"
      class="ag-theme-balham"
      [rowData]="data"
      [columnDefs][="columnDefs"
      [defaultColDef]="defaultColumnDefs"
      (gridReady)="onGridReady($event)"
      (gridSizeChanged)="onGridSizeChanged($event)
</ag-grid-angular>
onGridReady(params: GridReadyEvent) {
  params.api.sizeColumnsToFit();
}

onGridSizeChanged(params: GridSizeChangedEvent) {
  params.api.sizeColumnsToFit();
}

I see your grid takes 100% width, make sure the parent div has a fixed width.我看到您的网格采用 100% 宽度,请确保父 div 具有固定宽度。 To center the grid, I see you have done justify-content: center;为了使网格居中,我看到你已经完成了justify-content: center; which is good but make sure this div has display: flex;这很好,但要确保这个 div 有display: flex; on it.在上面。

gridSizeChanged will be called every time the grid size changes and then we call sizeColumnsToFit so this will shrink all columns to fit with the fixed width.每次网格大小更改时都会调用gridSizeChanged ,然后我们调用sizeColumnsToFit以便缩小所有列以适应固定宽度。

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

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