简体   繁体   中英

How to make cell content in ag-grid centered vertically?

I am trying to decrease the row height of ag-grid by setting gridOptions.rowHeight . While this indeed decreases the row height, but the content is not centered vertically in the row. What's the best way to do this?

I also tried changing the grid-size parameter of the theme, but it runs into the same issue.

Here's the grid without any gridOptions . I measured the row height to be 42px (although the docs say that it should be 25px ).

在此处输入图片说明

Here's what I get when I reduce the row height to 36px ( gridOptions={{ rowHeight: 36 }} ):

在此处输入图片说明

Notice that the content is no longer vertically centered.

This becomes even more apparent when I increase the row size to 100px . The content is clearly not centered.

在此处输入图片说明

Cell content can be vertically aligned using css only.

.ag-cell {
  display: flex;
  align-items: center;
}

You can also add inline styles in the column definitions.

<AgGridReact
  rowHeight={50}
  defaultColDef={{
    cellStyle: (params) => ({
      display: "flex",
      alignItems: "center"
    })
  }}
  {...}
/>

Live Demo

编辑 64058096/减少农业网格中的行高

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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