Adding an icon to the header for a Spark DataGrid

Adding a static icon to the header of Spark DataGrid is very easy. You will need to create a custom  headerRenderer and specify it for your GridColumn. Here are the steps:

1. Copy the contents of the skin file: DefaultGridHeaderRenderer.mxml and paste it into a new mxml f ile that will be used as your custom headerRenderer.

2. In the custom header renderer, find the HGroup at the end of the skin file. Add a BitmapImage as the first element in the HGroup (before the ‘labelDisplay’ Group).

<s:BitmapImage source="beer.JPG" />

3. You might want to make some padding or gap changes to the HGroup to position your icon. This example changed the gap to 8.

4. Specify this custom headerRenderer for your GridColumn:

<s:GridColumn id="c1_2" dataField="name" headerText="Pub Name"
    headerRenderer="IconHeaderRenderer2"/>

Voila! It’s simple. Note, if you wanted to modify the sortIndicator, you can also do it by creating a custom header renderer based off of the default one.

Sample Code: IconHeaderExample.mxml, IconHeaderRenderer.mxml IconHeaderRenderer2.mxml

5 responses

  1. […] Adobe’s Joan Lafferty continues to share her examples of new Flex components by this week showing how to add an icon to the header for a Spark DataGrid. […]

  2. can we add dynamic, using xml as source for headerRenderer images for a given columns?

  3. […] Adding an icon to the header for a Spark DataGrid « Flex Butterflies …Feb 16, 2011 … Adobe’s Joan Lafferty continues to share her examples of new Flex components by this week showing how to add an icon to the header for a … […]

  4. How to get the source code , when I am trying to open it’s redirecting to icloud.com page

    1. 😦 Sorry, I wasn’t on top of things when mobile me ended and all the files I put up there have vanished, so, you can’t download them anymore.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: