Change color of a table row

In my recipe table the sum of my elements must make 100%. I would like to make my code so that if the sum of my elements is not 100% then color red the entire row.

Which is the most appropriate way to achieve this functionality?

Regards

Can you post a sample of what the table looks like?
Are you using 7.7 or earlier?

try making another column that is the value 1 if the row does not add up to 100% and the value 0 if it does add up to 100%.

Then on your table make the background mode property mapped. Then in the table customizer go to the background color mapping tab and setup keys on your new column with the colors you want.

I read about this in a forum thread. But I didnt have time to try it.
How should I set up this column in the table? Should it be done in mySQL.
Can I do it with the mySQL workbench?

I apologize if my questions look silly or as it may look like I want you to do my homework, but this is not done on purpose. It is because it is my first project with ignition. My background is with WinCC.

You can make this part of the query, and not have to alter the table at all…

Are the element entries in percentages? If so, then something like:SELECT element1, element2 ,element3 ,element4 ,element5 , (element1 + element2 + element3 + element4 + element5) as total will give you a total column. You can then map it to 100.

If it is not already in percentages, then something like:SELECT element1, element2 ,element3 ,element4 ,element5 , (element1 + element2 + element3 + element4 + element5) / goalTotal as total will give you a total column. You can then map it to 1.

When you say I should make that part of the query, which query do you refer to? Where should it be placed?

Regards

Ok, let’s back up a moment. It’s likely I’m missing something… How are you currently populating your table? Based on other threads, it seems it is by an editable table linked to a database table.

I am indeed using an editable table to populate my table.
I added a column in my table called “check_sum” where I want to set it to the sum of my recipe element percentages.
I tried the following query in mySQL workbench and it works.
“SELECT R0_4, R4_8, (R0_4 + R4_8) as check_sum FROM recipes”
The problem is I dont know where exactly it should go in my cell edited event script which I use to make my table edited. The script is as follows

row = event.row
col = event.column
colName = event.source.data.getColumnName(col)
value = event.newValue
id = event.source.data.getValueAt(row, 0)
query1 = “UPDATE recipes SET %s = ? WHERE ID = ?”
query2 = “SELECT R0_4, R4_8, (R0_4 + R4_8) as check_sum FROM recipes”
system.db.runPrepStmt(query1 % colName, [value, id])

Where should query2 be called?

Sorry for the late reply, Nik…

What I was envisioning was to add the summing column to the query the populates the table no need to add a column to the database.

Whatever changes to the cell, can keep on as it was, with maybe the exception of adding all the elements together and checking for 100% before writing to the table.

Can you please give me some hints on how to implement your suggestion?

It’ll take a bit of time, but I’ll put something together for you. :slight_smile:

Hi Nik,

Got something put together for you (finally).

Zip file contains:
– A MySQL file that may be imported into your system. This will create a new schema called JCC (being my initials, I’m pretty sure most people won’t have this :wink: ) and a table called jcc_recipe
– A window that lets you edit the sample db table.

Be sure to look at the binding on the Data Property, the ‘ndx’ Custom Property, and the Table Customizer (a couple of the columns are hidden and working behind the scenes)

Hope this helps!
JCC_Recipe.zip (10.6 KB)

Thanx Jordan. I am out of the office for a few days. I will check it out on Saturday.

Regards