Wednesday, February 20, 2008

Alternate row color in DataGrid per DataGridColumn

The idea came from a flexcoders post here. After attempting the previous example of row background colors in ADG I thought it should be easy to achive this which resulted in this post.

I extended the DGColumn and added a "alternatingItemColors" style it so that it would be possible to set it per column.

I extended the DGItemRenderer and used the background and backgroundColor properties to set the items background color. I added logic in a overridden validateNow function to pick up the color from the alternatingItemColors color array.

The drawback of this approach is that the selection feedback gets almost hidden by the background coloring which would not be the case if the drawRowBackground function is overridden.

The result :

The source is available here.

5 comments:

Unknown said...

Hi Sreenivas,

Can we achieve something similar to 'groupedColumns in advanceddatagrid' in datagrid?

I am using flex 2 and my requirment is I need to merge two columns

Sreenivas said...

It would not be possible with DG because the layout logic for this is not currently present in DG. You need to add that logic.

Unknown said...

Hi Sreenivas,

Could u pls help me in acheiving that logic? It is very urgent.
I am new to flex and I have no idea of modifying the layout logic.

Thanks in advance.

Sreenivas said...

It is not a very simple logic to add and I am not available for this kind of work.

Unknown said...

Hi Sreenivas,

I will try to implement it by myself.

Thanks for your guidance.