Changing the color of table record by every second record

Hello team

I would like to switch color of my dynamic records.

I have dynamic tables and thinking is it possible to set background always to white for first record, gray to second one and again wait for next one?

image

color change pleasantly

Let me know if we can use script for this

Hello,
you can use the pseudo-class :nth-child(even) to do so.
The css would be like this:
.table tbody tr:nth-child(even) {
background-color: #8c8c8c;
}
You could find more information on it on this page:
https://help.objectiflune.com/en/pres-connect-user-guide/2022.1/#designer/Styling_Formatting/Styling_A_Table.htm#toc-5

I hope this will help you.

Not really working in my case because I am enabling details records using table script in Connect template.

So it works fine for record 1 in template, but when I switch to next record its not working (all records have a colors instead)

I created a script for doing this:

results.each(function(index)
{
	if(index % 2 == 1) {
		this.css('background','white');
	}
	else {
		this.css('background','yellow');
	}

});

It works fine for first record but when I switch to next record, then all details are yellow. @Yann

Perhaps you could do this:

results.filter(function() {
	return this.css('display') != 'none';
}).each(function(index) {
	this.css('background', index % 2 == 1 ? 'white' : 'yellow');
});

Note: You’ll need to make sure that this script is placed below the scripts that conditionally hide table rows, so that it runs later.

1 Like

It changed colors very nice and smooth way.

Thank You @Sander