DEV Community

Cover image for AG Grid Tip: HeaderNames
Stephen Cooper for AG Grid

Posted on • Edited on

3

AG Grid Tip: HeaderNames

Did you know that you don't always have to provide a headerName to your column definitions in AG Grid?

Why? AG Grid will do a best guess at providing a human readable header based off your field name. So make sure you are not doubling your configurations by manually setting the same header name that the grid provides for you.

Simple Field Names

For example, if your field is athlete then AG Grid will capitalise it to give the header name Athlete.



columnDefs:  ColDef[] = [   
  { field: 'athlete' }
];


Enter fullscreen mode Exit fullscreen mode

Athlete Header Name

Camel Cased Fields

If your field is myCustomFieldName then AG Grid will provide this header name for your column: My Custom Field Name.



columnDefs:  ColDef[] = [   
  { field: 'myCustomFieldName' }
];


Enter fullscreen mode Exit fullscreen mode

My Custom Field Name

As you can see the default header name is produced by splitting on capital letters and capitalising the first which is often what you want.

Manual Header Names

Of course you can always override the default and set the headerName property manually but only do this when you need to and keep you column definitions clean!



  { field: 'athlete', headerName: 'Best Athlete' } 


Enter fullscreen mode Exit fullscreen mode

Using HeaderName

ValueGetter Header Names

You can also use the callback headerValueGetter which is useful for customising the header based on the callback parameters.



  { field: 'athlete', headerValueGetter: (params) => 'New Athlete' 


Enter fullscreen mode Exit fullscreen mode

Using headerValueGetter

For further reference see these properties in the AG Grid Docs

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay