整个网格的ag-grid自动高度

时间:2017-01-26 18:40:06

标签: ag-grid

我找不到一个很好的方法来调整网格大小以完全适合所有行。

documentation仅指向按%或px调整大小。

由于我希望它基于行的大小,我想出了以下功能。好像我正在重新发明轮子,所以也许有更好的方法?

getHeight(type:EntityType) {
    var c = this.Apis[type] && this.Apis[type].api && this.Apis[type].api.rowModel // get api for current grid
        ? this.Apis[type].api.rowModel.rowsToDisplay.length
        : -1;
    return c > 0
        ? (40+(c*21))+'px' // not perfect but close formula for grid height
        : '86%';
}

必须有一个不那么混乱的方式..

7 个答案:

答案 0 :(得分:6)

我遇到了这个解决方案:

这个问题有2个答案。

1)如果您使用的是低于v10.1.0的任何内容,那么您可以使用以下CSS来解决问题:

.ag-scrolls {
    height: auto !important;
}

.ag-body {
    position: relative !important;
    top: auto !important;
    height: auto !important;
}

.ag-header { 
    position: relative !important;
}

.ag-floating-top {
    position: relative !important;
    top: auto !important;
}

.ag-floating-bottom {
    position: relative !important;
    top: auto !important;
}

.ag-bl-normal-east,
.ag-bl-normal,
.ag-bl-normal-center,
.ag-bl-normal-center-row,
.ag-bl-full-height,
.ag-bl-full-height-center,
.ag-pinned-left-cols-viewport,
.ag-pinned-right-cols-viewport,
.ag-body-viewport-wrapper,
.ag-body-viewport {
    height: auto !important;
}

2)任何高于v10.1.0的东西,现在都有一个名为'domLayout'的属性。

答案 1 :(得分:0)

使用此:

static public List<Individual> listIndividuals(Model model){
    OntModel ontModel = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_RDFS_INF, model);
    return(ontModel.listIndividuals().toList()); // property is an element of this list where it shouldn't be
  }

Reference

答案 2 :(得分:0)

onGridReady 函数上添加以下代码以实现自动宽度和自动高度

onGridReady = params => {
   // Following line to make the currently visible columns fit the screen  
   params.api.sizeColumnsToFit();

   // Following line dymanic set height to row on content
   params.api.resetRowHeights();
};

参考 Auto Height Auto width

答案 3 :(得分:0)

如果以下是标记

<ag-grid-angular
  #agGrid
  id="myGrid"
  class="ag-theme-balham"
  [columnDefs]="columnDefs"
  [rowData]="rowData"
  [domLayout]="domLayout"
  [animateRows]="true"
  (gridReady)="onGridReady($event)"
></ag-grid-angular>

请注意, [domLayout] =“ domLayout”

将其设置为 this.domLayout =“ autoHeight”; ,即可完成。.

参考:

https://www.ag-grid.com/javascript-grid-width-and-height/

https://next.plnkr.co/edit/Jb1TD7gbA4w7yclU

希望有帮助。

答案 4 :(得分:0)

determineHeight() {
    setTimeout(() => {
      console.log(this.gridApi.getDisplayedRowCount());
      if (this.gridApi.getDisplayedRowCount() < 20) {
        this.gridApi.setDomLayout("autoHeight");
      }
      else {
        this.gridApi.setDomLayout("normal");
        document.getElementById('myGrid').style.height = "600px";
      }
    }, 500);
  }

答案 5 :(得分:0)

您可以在“配置”列中使用ag-grid功能AutoHeight = true。或者,如果您要动态计算高度,则应使用getRowHeight()回调并创建divspan之类的DOM元素,并在其中添加文本,然后div将给它OffsetHeight,那么您将看不到任何数据/行的裁剪。

希望这会有所帮助。

答案 6 :(得分:0)

您现在可以通过设置 domLayout='autoHeight' 属性或调用 api.setDomLayout('autoHeight')

来自动化网格高度

参考Grid Auto Height