I have a Perspective table in 8.1.35 running a named query on a database table of 50 rows of workstation IDs and names and their status. Some workstations are turned on and some are turned off (their status).
How can I style the workstations that are turned on as shades of light green and dark green? And then how can I style the workstations that are turned off as shades of light red and dark red?
I think I can apply CSS here on odd and even rows but my strategy isn't working out currently.
Have named query return format set to json.
Have script transform work through list of workstations and set style classes to redCustom or greenCustom.
The table works as expected if I feed in a path to a regular style path such as "tables/rows/green/dark". The table also works as expected if I change my CSS to the following:
It's not necessary to use the stylesheet to get your custom colours. Just create style classes called redCustom and greenCustom and set the background colours of these as required
Because you're overwriting one setting with a second setting, and so you'll only ever see the second setting applied. If you want different colors, you need different rules.
And @amy.thompson is correct. If you actually create these named styles you're declaring, then this use of the stylesheet.css resource is unnecessary and would result in conflicting values later in development if you ever change one or the other.
When you are populating your data and configuring each object, you apply the style with logic:
# assume you're building your list of objects from some list of data
style_map = [
0: "greenCustom",
1: "redCustom"
]
rows = []
for entry in value:
rows.append({"Workstation": {"justify": "center", "style": {"classes": style_map.get(entry["someKeyToCheck"])}, "align": "center", "value": entry["name"]})
return rows
This results in each row having the value for classes be applied based on the value of the "someKeyToCheck" attribute of each row, where the end value is retrieved from some dictionary (this exmaple assumes your value is an int) .
It seems I have created an instance of an XY Problem and I apologize for that.
The reason I want to overwrite the odd / even rows with CSS is because when I go to sort a colored table (using regular styles for example which I have done) I might get an instance where I have several dark red rows in a row. The style applied to the JSON follows with whatever I sort the rows by in a session.
As far as I know there is no event associated with sorting a table so i can't retrigger styling all the rows.
If I am only using 1 shade of color I can (light green and dark green) I can apply that to the striped property on the table no issues.
So what I am really looking for is a way to say this row is always "green" and then CSS decides that the odd rows are light green and the even rows are dark green.
I hope that clarifies the real problem I am trying to solve.
Possibly with the stylesheet by applying a brightnessfilter on the even/odd rows; not sure how best to write the CSS selector to target the appropriate visible rows.
One thing to note is that the stylesheet.css resource rules are applied to ALL tables in the project. If you only want this for a specific table, I highly recommend supplying a meta.domId property for your Table and supplying a unique value, then modifying the rule to only target this Table: