cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ZachyV
Level 8

Alternate color in GalleryForm rows

Is it possible to do an alternate color in rows in a gallery?

2 REPLIES 2
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Alternate color in GalleryForm rows

Short answer - no (at least not easily). Since there's no way to get the current index of the row in the gallery, you cannot use some formula to alternate the template fill color which would be alternating for even and odd indices. Please consider creating a new feature request in the PowerApps Ideas board for that.

 

Long answer - maybe. If you know that the collection won't have more than a certain number of elements, and delegation is not an issue, then there is a contrived way for that. Basically, we would create a new collection which would contain the element indices, and the original element. And you would use that second collection as the Items property of your gallery.

 

Here's an example (you can also download the attached app, open it in PowerApps Studio, and see it for yourself). I have a collection ('ScoobyDoo') that has some of the characters of that show. I'll use a ForAll function to loop over a collection containing all possible indices ([1, 2, 3, 4, 5, ..., <max number of elements>]), and add to the second collection the corresponding element from the original table, using the FirstN and Last functions to extract an element at that index:

Clear(scooby2);
ForAll(
    FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16], CountRows(ScoobyDoo)),
    Collect(
        scooby2,
        {
            Index:Value,
            Item:Last(FirstN(ScoobyDoo, Value))
        }
    )
)

The expression above would work up to 16 items; if in your case your data source can have more than that, then you would need to add more numbers to that local table.

 

In the gallery we can then set the TemplateFill property to an expression that would alternate colors between lines:

RGBA(
    0,
    0,
    If(Mod(ThisItem.Index, 2) = 0, 255, 0),
    0.1)

As you can see, it's technically possible to do that (if your data source is small), but it would be better if the language had a better support for this.

Lode
Level: Powered On

Re: Alternate color in GalleryForm rows

Is it still not possible ?

Would be a nice feature Smiley Happy

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 54 members 4,817 guests
Please welcome our newest community members: