How can I center the text in the headers for an AG-grid control?

前端 未结 9 1211
长情又很酷
长情又很酷 2021-02-19 00:22

How can I center the text in the headers for an AG-grid control? I have tried using cellstyle and cellclass in the column definition but that did not work. Thank you

9条回答
  •  时光说笑
    2021-02-19 01:09

    A more complete solution I've been using for a while now, is to create a column definition helper like this:

    export const columnCentered = {
      headerClass: 'text-center',
      cellStyle: {
        textAlign: 'center'
      }
    }
    

    then add the following to your style.scss

    .ag-header-cell.text-center {
      .ag-header-cell-label {
        justify-content: center;
      }
    }
    

    finally you can easily use it like this:

    columnDefs: [
      { field: 'normalCol' },
      { field: 'centeredColA' ...columnCentered },
      { field: 'centeredColB' ...columnCentered }
    ]
    

提交回复
热议问题