Sunday, August 11, 2013

Alternating Row Colors - Spark DataGrid

Just figured I'd toss this here, since this seemed to mess with me more than it should.

I've recently started a project in Flex 4.6 using MXML for the first time.

One of the things I needed to interact with was the Spark DataGrid component.

I needed to have alternating row colors. This seemed like an easy enough task, but everywhere I looked the solution was either set a property that no longer exists, or having me go through making a new skin to add this kind of functionality.

Or, maybe I'm just dumb an didn't recognize that the oft-referred to "alternatingRowColors" property wasn't a property, but a style. So the next step is trying to use this style, which takes an array.

So, here's the solution to change that property in MXML nicely and easily.

<fx:style>
@namespace s "library://ns.adobe.com/flex/spark";
s|DataGrid {
 alternatingRowColors: #DEDEDE, #E8E8E8;
}
</fx:style>

Keep in mind, that will style every DataGrid. Otherwise, you can just style an individual one like so:

<fx:style>
@namespace s "library://ns.adobe.com/flex/spark";
s|DataGrid#myDataGridID {
 alternatingRowColors: #DEDEDE, #E8E8E8;
}
</fx:style>

Where "myDataGridID" is the id property of your MXML DataGrid.

No comments:

Post a Comment