Perspective table selection data issue

Hi,

I'm having some troubles with a perspective table that is styled based on row.

When i select a row, the data returns correctly in props.selection.data[0]:

{
  "DocEntry": 79,
  "LineNum": 15,
  "PlannedQty": 693.6,
  "IssuedQty": 693.6,
  "BaseQty": 0.24605,
  "IssueType": "M",
  "ItmsGrpCod": 101,
  "VisOrder": 1,
  "Balance": null,
  "ItemCode": "2009",
  "UomEntry": -1,
  "ItemName": "C",
  "UomCode": "Manual",
  "ItemType": 4,
  "StartDate": 1746550800000,
  "EndDate": 1746982800000,
  "BaseQtyNum": 0.003468,
  "Status": "P",
  "UpdateDate": 1747682210147,
  "Operator": "admin",
  "json_data": "[{\"batchno\":\"batfch\",\"amount\":1},{\"batchno\":\"asdasd\",\"amount\":32}]",
  "OrderItemStatus": "Preparing",
  "column_40": "",
  "column_41": "",
  "column_42": "",
  "column_47": "",
  "column_48": "",
  "column_49": "",
  "column_43": "",
  "column_44": "",
  "column_45": "",
  "column_46": "",
  "column_50": "",
  "column_29": "",
  "column_25": "",
  "column_26": "",
  "column_27": "",
  "column_28": "",
  "column_23": "",
  "column_24": "",
  "column_30": "",
  "column_31": "",
  "column_36": "",
  "column_37": "",
  "column_38": "",
  "column_39": "",
  "column_32": "",
  "column_33": "",
  "column_34": "",
  "column_35": ""
}

But when i refresh the binding I sometimes get the 'style' as an object in the array:

{
  "DocEntry": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 79
  },
  "LineNum": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 15
  },
  "PlannedQty": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 693.6
  },
  "IssuedQty": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 693.6
  },
  "BaseQty": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 0.24605
  },
  "IssueType": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "M"
  },
  "ItmsGrpCod": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 101
  },
  "VisOrder": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 1
  },
  "Balance": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": null
  },
  "ItemCode": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "200019"
  },
  "UomEntry": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": -1
  },
  "ItemName": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "C"
  },
  "UomCode": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "Manual"
  },
  "ItemType": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 4
  },
  "StartDate": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 1746550800000
  },
  "EndDate": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 1746982800000
  },
  "BaseQtyNum": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 0.003468
  },
  "Status": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "P"
  },
  "UpdateDate": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": 1747682210147
  },
  "Operator": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "admin"
  },
  "json_data": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "[{\"batchno\":\"batfch\",\"amount\":1},{\"batchno\":\"asdasd\",\"amount\":32}]"
  },
  "OrderItemStatus": {
    "style": {
      "backgroundColor": "#FCBF49"
    },
    "value": "Preparing"
  }
}

Can you show your binding?

Variable:

Table:

Transform script from the ignition documentation:

def transform(self, value, quality, timestamp):
    data = []
    for row in value:  # Loop over each row.
        keys = row.keys()  # Determine the keys in use for the row.
        if row["OrderItemStatus"] == 'Prepared' :  # If the population in THIS row is more than 1000000...
            style = {"backgroundColor": "#5bde6a"}  # the style should be this.
        elif row["OrderItemStatus"] == 'Preparing':
        	style = {"backgroundColor": "#FCBF49"} 
        else:
            style = {"backgroundColor": ""}  # Otherwise, the style should be this.
            
        # This next line builds an object/dictionary which contains value and style keys for 
        # every cell in the row. The value key will be used to store the true value of the 
        # object, while the style key will be used to define the appearance of the CELL. 
        # Since our goal is to style all cells in this row in the same manner, we are re-using 
        # the same style value across all cells in this row.
        formatted_rows = [{"value": v, "style": style} for v in row.values()]
        
        # Here, we make a proper python dictionary out of the known keys
        # and our formatted cells.
        row_dict = dict(zip(keys, formatted_rows))
        data.append(row_dict)  # Now append this new dictionary to our new data array/list.
    return data  # Finally, return our newly formatted data.

I have the same issue. Were you able to fix it?

No

Can I ask, if you want all the rows to be styled the same, why are you putting a style binding in the row transform? Based on the binding, I would expect style to show up in the data always.

Not sure if I will be able to help. Could you explain the sometimes, what conditions lead to it adding style, and what dont? I would be tempted to add a logger and see if the transform is running on basic selections, or only on the refresh bindings.

Hi, I dont want all rows to be styled the same:

The sometimes is just random. Selected the same row with the same data gives different results at different points in time.

    if row["OrderItemStatus"] == 'Prepared' :  # If the population in THIS row is more than 1000000...
            style = {"backgroundColor": "#5bde6a"}  # the style should be this.
        elif row["OrderItemStatus"] == 'Preparing':
        	style = {"backgroundColor": "#FCBF49"} 
        else:
            style = {"backgroundColor": ""} 

Oh whoops, I had looked through the json and they all had the same background color assigned, so I thought that was the goal.

For me, this only seems to happen when the query binding has polling turned on and the styling for the background color is dynamically set for a row or cell using a script transform, but I'm able to consistently reproduce this.