简体   繁体   English

如何在 React.js 的 Ag-Grid 中居中对齐表格

[英]How to center align tables in the Ag-Grid in React.js

I am new to Ag-Grid React, I have created the table but by default, they are aligned on the left side.我是 Ag-Grid React 的新手,我已经创建了表格,但默认情况下,它们在左侧对齐。 Can anyone tell me how to center align tables in AgGridReact ?谁能告诉我如何在AgGridReact中居中对齐表格?

You can apply certain style on the column by declaring aCellStyle object in the column definition.您可以通过在列定义中声明CellStyle object 来在列上应用特定样式。 If you want all columns to be centered:如果您希望所有列居中:

<AgGridReact
  {...props}
  defaultColDef={{
    cellStyle: () => ({
      display: "flex",
      alignItems: "center",
      justifyContent: "center"
    })
  }}
/>

However if you only want to center align a specific column, put the cellStyle object in that column definition instead:但是,如果您只想居中对齐特定列,请将cellStyle object 放在该列定义中:

{
  headerName: "Country",
  field: "country",
  width: 120,
  cellStyle: () => ({
    display: "flex",
    alignItems: "center",
    justifyContent: "center"
  })
},

Live Demo现场演示

编辑 66820891/how-to-aligncenter-for-tables-in-the-ag-grid-in-react-js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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