Changing colour of row based off value in cell in perspective table

If you want to style individual cells or even a row based off of a value within a row, then you need to provide that as part of the data. The default data in the Table has a simple application of this which you can see for the city of Folsom.

You will want to manipulate your data so that each cell contains a style object, which in turn contains a property key of backgroundColor, where this property has the color you want the cell to have. If you want a cell to not have any additional background, you can leave the cell as a simple value.

In this example, you can see that I’ve kept the original orange background for my city cell, but Ive added a green background to my country cell by providing the cell’s data as an object with value as a key (which is where the displayed value should go) and a style object with an internal backgroundColor property.


I usually include a transform on whatever binding I’m using for my Table data:

	returned_rows = []
	for row in value:
		row_dict = {}
		row_dict['country'] = row.country
		row_dict['city'] = row.city
		population = row.population
		if int(population) < 3000000:
			population = {'value': population, 'style': {'backgroundColor': '#00FF00'}}
		row_dict['population']= population
		returned_rows.append(row_dict)
	return returned_rows

This allows for easy highlighting of values which match a condition:

4 Likes