如何使ag-grid中的单元格内容垂直居中?

时间:2020-09-25 05:04:04

标签: css ag-grid ag-grid-react

我正在尝试通过设置gridOptions.rowHeight来降低ag-grid的行高。虽然这确实降低了行高,但是内容并未在行中垂直居中。最好的方法是什么?

我也尝试过更改主题的grid-size参数,但是遇到了同样的问题。

这里是没有任何gridOptions的网格。我测量的行高为42px(尽管文档说应该为25px)。

enter image description here

将行高度降低到36pxgridOptions={{ rowHeight: 36 }})时,我得到的是这样:

enter image description here

请注意,内容不再垂直居中。

当我将行大小增加到100px时,这一点变得更加明显。内容显然没有居中。

enter image description here

1 个答案:

答案 0 :(得分:2)

单元格内容只能使用CSS垂直对齐。

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

您还可以在列定义中添加内联样式。

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

实时演示

Edit 64058096/decreasing-row-height-in-ag-grid