571
Views
6
Comments
Solved
[OutSystems Data Grid] Set Row background depending on cell value
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive

It is a bit more complicated than the title says. 

I have a list of entities for shopping, where each order can have multiple Articles. By default the background for each row is white for even rows and light grey for odd, but I want it to change background color depending on the order. I will attach an example of this:

Something like the picture above, in a way that all the order with the same id are of the same color, and the colors alternate.

Is there any way to do this for the datagrid component?

2020-08-05 09-00-16
Gabriel Lundgren
Solution

Hey Takeru,

As of now, our grid doesn't have this built-in, but we do have a workaround for you.
To achieve this you could something like this. On your grid initialize event, add a similar JS snippet

In my case, I added red or blue according to Sample_Product.Id, so you would have to change this according to your dataItem and desire.


I've attached an OML that contains this solution.

In case you have any doubts feel free to reach out,

Best regards,
Gabriel Lundgren

SetRowBackground.oml
2021-08-12 05-19-40
Shubham Janbandhu

Hi Takeru,

Thank you for query. Could you please refer this link Change row color.

Regards,

Shubham

2020-08-05 08-52-58
Ruben Goncalves

Hi @Shubham Janbandhu,

The question is about the DataGrid component, not the Table Record widget...

Next time, please read more carefully the question.

Cheers,
RG

2021-08-12 05-19-40
Shubham Janbandhu

Thank you, Ruben.

Definitely will try on it and come up with good solution.

Cheers,

Shubham

2020-08-05 09-00-16
Gabriel Lundgren
Solution

Hey Takeru,

As of now, our grid doesn't have this built-in, but we do have a workaround for you.
To achieve this you could something like this. On your grid initialize event, add a similar JS snippet

In my case, I added red or blue according to Sample_Product.Id, so you would have to change this according to your dataItem and desire.


I've attached an OML that contains this solution.

In case you have any doubts feel free to reach out,

Best regards,
Gabriel Lundgren

SetRowBackground.oml
UserImage.jpg
Daniele Betti

Hi all, I tried your solutions and others solutions in the community, but I still have the problem that cannot override the default background color of even rows.

It seems that the DataGrid css background color has higher priority of mine... any suggestions?

UserImage.jpg
Michael Hoffmann

If CSS priority is the problem, you can solve it by making your own rules "stronger". 

The !important tag is there if you want a big hammer, otherwise you might try doubling up on the selectors. Here's some reading on the topic:

https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

note that even using the same selector twice (like .myclass.myclass) will give your rule a weight of "two class selectors", which can let it ovverride rules with only one class selector.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.