A user recently posted this question on the Community Answers forum:
“...Looking to have alternative row colors in live data... There is no interactive part about this, just want to break up the colors of each row...”
It’s a good question, so I decided to elaborate a little bit in this blog.
Like so many things in the software, there are multiple ways to approach this. The first way is to create a background image with alternating colors, and just stick it behind your Live Data item. I don’t want to discredit this approach because it's simple, fast and works in a number of scenarios. However, it does lack a lot of flexibility. If you ever need to adjust the heights of your rows, or you need to use Group-By band, or you want to highlight every third row or any number of other intricacies, you’ll probably need a different solution.
A second (perhaps more flexible) method is to adjust the formatting inside the Live Data utilizing the row number. Content Player has a bunch of built-in markup text values in Live Data, including &row, &rows, &page, &pages, &band and &bands. We can get the count (or index) of any given row using &row. In any live data item, drag a Markup Text field down into your row, and paste in the following expression:
When you preview the sign, you’ll see that every even row now has the word EVEN, and every odd row has the word ODD. Let’s break down what’s happening here.
Inside the expression, [&row] returns the current row number. We are then taking that value mod (%) 2. If “mod 2” sounded like Greek to you... well... it’s close! Modulus (Latin) is a mathematical operator that returns the remainder (or leftover) when dividing two numbers. So “[&row] % 2” is returning whatever value is left over when dividing the row by 2. If there is no remainder, the row number is even. Otherwise, the row must be odd.
So using this, you can then change those EVEN and ODD values to whatever you want. If you want to have an image show on each even row, you could do something like this:
Or if you wanted to reference an image in your build:
Note: When using the content:// syntax, your content name can't have any spaces or special characters in the name.
If you’re interested in this kind of stuff, I’d encourage you to check out the Expression Overview, which has tons of great information on using expressions, like the ones above.
That’s it for this edition. #DoYouFWI?