Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-grid table: Vertical-align: middle

I am using the framework ag-grid () I have changed the row-height to 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>

Sadly, I can not manage to center the cell vertically.

I have tried to change many classes, including ag-cell. My css I tried:

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

But the cell isn`t centered: enter image description here

like image 468
Paul Avatar asked Nov 29 '18 13:11

Paul


People also ask

How do you center AG grid table?

Then in your ag-grid column definition use your custom css style in the cellClass property. Show activity on this post. cellStyle: { 'height': '100%', 'display': 'flex ', 'justify-content': 'center', 'align-items': 'center ', }, it's work for me.

How do you right align text in Ag grid?

Just add type: 'rightAligned' property.

How do you change the row height in Ag grid?

To change the row height for the whole grid, set the property rowHeight to a positive number. For example, to set the height to 50px, do the following: const gridOptions = { rowHeight: 50, // other grid options ... } Changing the property will set a new row height for all rows, including pinned rows top and bottom.

How do I add a checkbox to Ag grid?

To configure the column to have a checkbox, set colDef. headerCheckboxSelection=true . headerCheckboxSelection can also be a function, if you want the checkbox to appear sometimes (e.g. if the column is ordered first in the grid).


3 Answers

You can use below CSS. No need to use hard-coded values in CSS for height.

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

Have a look at this plunk: ag-grid: text-align vertically center

like image 63
Paritosh Avatar answered Oct 10 '22 22:10

Paritosh


To build on @Paritosh's answer...

You don't have to overwrite the ag-grid styles themselves. You can do something like this in your own stylesheet:

.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;
}

Then in your ag-grid column definition use your custom css style in the cellClass property.

var columnDefs = [
  {
    headerName: "Alerts",
    colId: 'invoice_issues',
    editable: false,
    cellClass: "cell-border cell-vertical-align-text-right",
    valueGetter: showInvoiceIssues,
    autoHeight: true,
  }
]
like image 27
Rob Carpenter Avatar answered Oct 10 '22 21:10

Rob Carpenter


You can set cell style to following

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

it's work for me.

like image 41
Afeesudheen Avatar answered Oct 10 '22 23:10

Afeesudheen