简体   繁体   English

Angular ag-grid 调整大小问题

[英]Angular ag-grid resize issue

I want to enable column resizing but in the same time I want to avoid the case when the user resize any column to the left side of the grid and doing this a blank space appers on the right of the last column.我想启用列调整大小,但同时我想避免用户将任何列调整到网格左侧的情况,并在最后一列的右侧出现空白区域。 I attached a picture below to explain what I'm trying to achieve.我在下面附上了一张图片来解释我想要实现的目标。

在此处输入图片说明

Something like this should do for you.这样的事情应该为你做。 Main point is to listen for the columnResized event, then check if the current column size total is larger than the grid width, if so then use the sizeColumnsToFit function.重点是监听columnResized事件,然后检查当前列的总大小是否大于网格宽度,如果是则使用sizeColumnsToFit函数。 Be careful with this though;不过要小心; the sizeColumnsToFit function will try to maintain ratios of the columns, so perhaps you would prefer to size all the columns to 10px, then size to fit. sizeColumnsToFit函数将尝试保持列的比例,所以也许您更喜欢将所有列的大小设置为 10px,然后调整大小以适合。 It mostly depends on your use case and how you want it to behave.这主要取决于您的用例以及您希望它的行为方式。

This issue can be fixed by using columnResized event and sizeColumnsToFit() method of gridApi .这个问题可以通过使用columnResized事件和columnResized sizeColumnsToFit()方法来gridApi

component.ts:组件.ts:

onColumnResized(params) {
  if (params.source === 'uiColumnDragged' && params.finished) {
    this.gridApi.sizeColumnsToFit();
  }
}

component.html:组件.html:

<ag-grid-angular 
  #agGrid
  style="width: 100%; height: 100%;"
  class="ag-theme-balham"
  [columnDefs]="columnDefs"
  [rowData]="rowData"
  (gridReady)="onGridReady($event)"
  (columnResized)="onColumnResized($event)">
</ag-grid-angular>

If you want to fill the space within the rows, on column resize, then I would suggest overwriting the CSS.如果你想填充行内的空间,调整列大小,那么我建议覆盖 CSS。 At the time of writing the following worked:在撰写本文时,以下工作有效:

.ag-center-cols-container { width: 100% !important;}

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

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