Hello gentlemen, I have a problem with a table that I don't know how to solve:
I have a table that is populated by a sql query ==> return format as json:
So far so good everything works fine!
I wanted to color the background of the rows based on a value.
I changed the return format of the query from json to dataSet, (I used a script by @ynejati).
Changing backgroundColor based on a value works, but now the sum "Quantity" in the footer column no longer works and I don't know where I'm going wrong.
Why change the output to dataset to then re convert it to json ?
Keep the json as the base return, and add the style to it directly.
The sum doesn't work anymore because you changed the structure of the json.
I can't do much more right now, I have a sick kid to take care of, but I'll come back to it when I can.
"Why change the output to dataset to then re convert it to json ?"
I'm trying to persuade my company to switch to Ignition from other scadas and then I have to show something charming
"Keep the json as the base return, and add the style to it directly."
Yes, you're right, I just need to figure out how to do it
"The sum doesn't work anymore because you changed the structure of the json."
I imagined that was the problem, I just don't know how to point to the values of the new json structure.
I'll focus on keeping the json as the base return and add the style directly.
Can I possibly contact you if I can't?
I'm sorry that your kid is not well, I hope he gets well soon.
Can you copy and paste what the data looks like ?
And I mean the actual data, not the binding. You can just right click on the property and select copy.
Tip: while posting a screengrab is useful for seeing the context of your code, you should post the text of the code as well so that your readers can copy and edit it. See this topic if you're not familiar with code formatting on this site.
or is a boolean operator that acts as an expression, and automatically treats the inputs as booleans. So if the left hand expression is 'falsey' (such as an empty list, dict, or string), the right hand expression will be returned instead. It's equivalent to: data = value.filtered if bool(value.filtered) else value.data
Or more imperatively:
if value.filtered:
data = value.filtered
else:
data = value.data
My bad, I went a bit too fast and didn't test it.
I can't spot the parse error from here, maybe an indentation mismatch ? make sure every line start with exactly the same indentation, It can be 13 spaces, 2 tabs, whatever you like, as long as it's consistent.
Also try without the format flags: "{}".format(total), see if there's not something wrong here...
But I can spot a logic error though: line 2 should end with for row in data instead of for row in value
def transform(self, value, quality, timestamp):
if value.filtered:
data = value.filtered
total = round(sum(row.value['Quantita'] for row in data))
else:
data = value.data
total = round(sum(row.value['Quantita'] for row in data))
return "{}".format(total)
and I got following message:
line 4, in Attribute Error: object has no attribure 'value'
So I modified the code as follow:
def transform(self, value, quality, timestamp):
if value.filtered:
data = value.filtered
total = round(sum(v['Quantita'] for v in data), 0)
else:
data = value.data
total = round(sum(row.value['Quantita'] for row in data))
return "{:.9n}".format(total)+" kg"
and finally everything works as expected.
wow, what a long day!
thank you @pascal.fragnoud for your support
I hope your son is doing better