简体   繁体   中英

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. Can anyone tell me how to center align tables in AgGridReact ?

You can apply certain style on the column by declaring aCellStyle object in the column definition. 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:

{
  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

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