I am trying to render a view to the table cell. I have posted the screeenshots of how the value fro viewParams is set up and how params are bound to the view that i am using to render the cell.
if there is any other information that i can provide regarding the script or the table.Is this the right way to approach this
The data structure expected by your sub-view is:
FFT : xxx
value
key
count : x
timestamp : xx:xx
The data being supplied in the table cell's viewParams doesn't match:
FTT : xxx
value
TOTAL REPAIRS
count : x
timestamp : xx:xx
PTR SOCKET WELD
count : x
timestamp : xx:xx
H5985
count : x
timestamp : xx:xx
As a result, I suspect, the rendered view has no parameter values to use other than 'FFT'.
how should i change the data -structure inorder to make it similar to table cell's viewParams
It depends how you are generating it. Show us how. If it's a script then post formatted code (using the </> button).
def transform(self, value, quality, timestamp):
columns = []
data = self.props.data
header = {}
defects = {}
unique_products = set()
# Additional data structure for storing latest timestamps
latest_timestamps = {}
for row in value:
product = row['PRODUCT_CODE']
if row['RESULT'] != 'PASS':
timestamp = system.date.fromMillis(row['TIMESTAMP'])
if product not in unique_products:
obj = {"field": product, "render": "view", "justify": "center", "viewPath": "COMMON RESOURCES/MACHINES/FUSION/cell"}
view_params = {"FTT": None, "value": {}} # Initialize view_params
for i in data:
defect = i["DEFECT"]
if defect not in defects:
defects[defect] = {}
latest_timestamps[defect] = {}
if defect == "FTT" and row["PRODUCT_CODE"] == product:
ftt = i[product]
view_params["FTT"] = ftt
else:
current_timestamp = latest_timestamps.get(defect, {}).get(product, None)
if current_timestamp is None or timestamp > current_timestamp:
defects[defect][product] = i[product]
current_timestamp = system.date.format(timestamp,"HH:mm")
latest_timestamps[defect][product] = current_timestamp
view_params["value"][defect] = {"count": defects[defect][product], "timestamp": latest_timestamps[defect][product]}
obj["viewParams"] = view_params
columns.append(obj)
unique_products.add(product)
# Adding obj1 at the beginning
obj1 = {"field": 'DEFECT', "justify": "center", "width": 300, "strictWidth": True}
columns.insert(0, obj1)
return(columns)
You need to define what exactly you want displayed in each column. Since the view parameters can only support
{"value": {"key": {"count": x, "timestamp": xx:xx}}}
you can only pass through that data arrangement. Your code is creating dictionaries for each defect type it finds but your view doesn't support that arrangement.
Is this someone else's code that you are modifying? The question seems odd if it's your own.
the problem with the data is that the defects change every day. The keys with defect names changes but i wont be able to set that up for value param in the view. because the keys are not known beforehand. So i was asking for help to how to structure the data in the table columns viewParams so that i can read those values. Any ideas?I am not familiar with the way table columns take in the value of the viewParams.
I never worked out how (or if you could) do what you're trying to do. I had to create a params.rowData
object with all of the params to pass in in there. The table then automatically passes all of the column values into that object
The view you have created to embed can display one numeric value and a timestamp. What do you want to display when you have three defects as shown in your sample data?
Mock it up in Excel and post a screenshot.