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

前端 未结 9 1171
长情又很酷
长情又很酷 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 00:44

    You may use this property:

    cellStyle: {textAlign: 'center'}
    
    0 讨论(0)
  • 2021-02-19 00:45

    I'm using Angular 8 and AG-Grid is nested deep in some other component.

    I had to do this in order to make it work.

    .ag-header-group-cell-label {
          justify-content: center !important;
    }
    

    And, this strictly needs to be under styles.scss file and not in the component scss file. Or else, it will not work.

    Hope this helps someone.

    0 讨论(0)
  • 2021-02-19 00:48

    If you want to align your text right, left or center in ag-grid. Then use this:-

    cellStyle: { textAlign: 'right' }
    cellStyle: { textAlign: 'left' } 
    cellStyle: { textAlign: 'center' }
    
    0 讨论(0)
  • 2021-02-19 00:55

    It should be:

    .ag-header-cell-label {
      text-align: center;
    }
    
    0 讨论(0)
  • 2021-02-19 01:03

    I'm using react and I just added the following snippet to my Table component's .css

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

    I'm overriding the .css class class from ag-grid which I found via devtools inspection, and discovered it's using flexbox for display.

    See example (not react but same concept): https://embed.plnkr.co/O3NI4WgHxkFiJCyacn0r/

    0 讨论(0)
  • 2021-02-19 01:03

    To use a custom class, add headerClass: "text-center" to the column definition and css as follows:

    text-center * {
        justifyContent: center
    }
    
    0 讨论(0)
提交回复
热议问题