ag-grid table: Vertical-align: 中间

ag-grid table: Vertical-align: middle

我正在使用框架ag-grid () 我已将 row-height 更改为 50px。

<div 
  className="ag-theme-balham"
  style={{ 
    height: '90vh', 
    width: '100%',
    'font-size': '18px',
    'row-height': '50px'
    }} 
    >
    <AgGridReact        
        rowHeight={50}
        columnDefs={columnsTaenze}
        rowSelection={'multiple'}
        onFirstDataRendered={this.autoSizeAll}
        rowDragManaged={true}
        enableColResize={true}
        animateRows={true}
        rowData={this.props.tabledata}
        enableFilter={true}
        onRowDragEnd={this.onRowDragEnd}>
    </AgGridReact>
</div>

遗憾的是,我无法将单元格垂直居中。

我尝试改变了很多类,包括ag-cell。 我的 css 我试过:

.ag-cell{
    line-height: 50px;
    height: 100%;
    vertical-align: middle;
}

但是单元格没有居中:

您可以使用下面的CSS。无需在 CSS 中使用硬编码值作为高度。

.ag-row .ag-cell {
  display: flex;
  justify-content: center; /* align horizontal */
  align-items: center;
}

看看这个 plunk:ag-grid: text-align vertically center

以@Paritosh 的回答为基础...

您不必自己覆盖 ag-grid 样式。您可以在自己的样式表中执行类似的操作:

.cell-vertical-align-text-left {
  display: flex!important;
  align-items: center;
}

.cell-vertical-align-text-right {
  display: flex!important;
  flex-direction: row-reverse;
  text-align: right!important;
  align-items: center;
}

然后在您的 ag-grid 列定义中使用您在 cellClass 属性.

中的自定义 css 样式
var columnDefs = [
  {
    headerName: "Alerts",
    colId: 'invoice_issues',
    editable: false,
    cellClass: "cell-border cell-vertical-align-text-right",
    valueGetter: showInvoiceIssues,
    autoHeight: true,
  }
]

您可以将单元格样式设置为以下

 cellStyle: {
        'height': '100%',
        'display': 'flex ',
        'justify-content': 'center',
        'align-items': 'center ',
      },

对我有用。