Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use headerClass property of ag-grid in angular?

Recently I added a-grid grid to my angular project.

I want to change font-family of header of my grid. I know that there is a property named as headerClass and it is the place of header class definition. but when I applied this property nothing changed to my header font family.

It is html file:

<ag-grid-angular  style="width: 100%; height: 500px;"
                  class="ag-theme-blue"
                  [rowData]="gridOptions.rowData"
                  [columnDefs]="gridOptions.columnDefs"
                  [defaultColDef]="gridOptions.defaultColDef"
                  [enableRtl]="agGridPropeties.enableRTL"
                  [localeText]="localeTextPersian"
                  [rowSelection]="agGridPropeties.rowSelection"
                  [multiSortKey]="agGridPropeties.multiSortKey"
                  [pagination]="agGridPropeties.pagination"
                  [paginationPageSize]="agGridPropeties.paginationPageSize"
> 
</ag-grid-angular>

It is my class:

.my-header-class {
  font-family: tahoma;
  font-weight:bold;
}

and it is my ts file:

public gridOptions: any = {
  defaultColDef: {
    resizable: true,
    sortable: true,
    filter: true,
    headerClass: 'my-header-class'
  },

  columnDefs : [
    {headerName: 'Make', field: 'make'},
    {headerName: 'Model', field: 'model'},
    {headerName: 'Price', field: 'price'},
    {headerName: 'Country', field: 'country'},
  ],

  rowData : [
      { make: 'TOYOTA', model: 'Celica', price: 35000, country:'Japan'},
      { make: 'FORD', model: 'Mondeo', price: 32000, country:'USA'},
      { make: 'BENZ', model: 'C200', price: 100000, country:'Germany'},
      { make: 'LAMBORGHINI', model: 'Aventador', price: 350000, country:'Italy' }
  ]
}

But the column header font family is not as I expected.

Do you have any Idea?

like image 807
Blue Moon Avatar asked Dec 09 '25 08:12

Blue Moon


1 Answers

Look at below link.

stackblitz-ag-grid-header-class

I have made only one change, added encapsulation: ViewEncapsulation.None to apply css.

or you can put your css class to your main style.css/style.scss file

hope this would help you, let me know if you still have an issue with it.

thanks

like image 168
kushal shah Avatar answered Dec 10 '25 21:12

kushal shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!