Perspective Table Dynamic Row Highlight Based on Dataset Tag Value Match

Hi All,

I am working on an Ignition Perspective Table component.

My table data is coming from a Dataset Tag:
[default]IGBT_ROBOT_CELL_PROD/SAP_RES_Dataset

The table contains a column:
"Prod. Order No"

I also have another tag:
[default]IGBT_ROBOT_CELL_PROD/OrderNumber

Requirement:
Whenever the value of OrderNumber tag matches any row's "Prod. Order No", I want the entire row to be highlighted dynamically.

I tried:

  • Script Transform on props.data

  • props.rows.style.classes expression binding

  • Row style bindings

But since the table data originates from a Dataset Tag and Perspective internally converts rows into objects containing value/style properties, I am facing issues with row styling and expression syntax.

What is the recommended Perspective approach to dynamically highlight a row based on matching tag value with a dataset column value?

Thanks.

The canonical approach would be an expression structure binding on your table's props.data referencing the raw dataset and the order number tag. That would have a script transform to generate the row objects, styled or not per the comparison.

I don't like script transforms (mainly for performance), so I would use my Integration Toolkit to perform the above in a single expression binding. Something like this:

transform(
    {[default]IGBT_ROBOT_CELL_PROD/OrderNumber},
    forEach(
        {[default]IGBT_ROBOT_CELL_PROD/SAP_RES_Dataset},
        if(
            it()['Prod. Order No'] = value(),
            asMap(
                forEach(
                    it(), // key/value pairs of the row
                    it()[0], // column key
                    asMap(
                        'value', asMap(it()[1]), // column value nested
                        'style', asMap('backgroundColor', '#ff3333')
                    )
                )
            ),
            asMap(it()) // optimized unstyled conversion of a whole row
        )
    )
)

One to add to the wiki, @pturmel! (I can do it if you don't have time)

Please do.

Hi @pturmel

Thank you for your earlier suggestion on using Expression Structure binding with a Script Transform for dynamic row highlighting.

I implemented it and the row highlighting is working correctly — the matching Prod. Order No row gets highlighted as expected.

However, I am seeing an "Invalid Key" error inside the table component. I wanted to understand what is this error???

    # 1. Safely unpack the values from our Expression Structure
    dataset = value.get("myDataset")
    target_order = value.get("currentOrder")
    
    # Return empty if data is missing or bad quality
    if dataset is None or target_order is None:
        return []
        
    # 2. Define the highlight style (you can use background colors or Style Classes)
    # Highlight style for a match:
    highlight_style = {
        "backgroundColor": "#FFFFCC" # Soft yellow highlight
    }
    # Standard style for non-matching rows:
    normal_style = {}

    # 3. Convert the dataset to a PyDataSet so we can iterate through it easily
    py_data = system.dataset.toPyDataSet(dataset)
    
    # Get column names to structure our row objects properly
    headers = dataset.getColumnNames()
    
    # 4. Build the JSON structure Perspective expects
    output_rows = []
    
    for row in py_data:
        # Build the cell data dict for this row
        row_cells = {}
        for header in headers:
            row_cells[header] = row[header]
            
        # Check if this row's order number matches our target tag
        # Replace "Prod. Order No" with the exact spelling of your column header
        if str(row["Prod. Order No"]) == str(target_order):
            row_style = highlight_style
        else:
            row_style = normal_style
            
        # Combine the cells and the dynamic row style into the required Perspective object
        output_rows.append({
            "value": row_cells,
            "style": row_style
        })
        
    return output_rows

Yes, Perspective, in the designer, doesn't like keys for mapping objects that have spaces or special characters (basically, keys that are not valid variable names). Not a problem for datasets, but you can't style a dataset.

(This is true whether you generate the problem column names with a transform script, or my expressions, or just by having a query binding return JSON format.)

The simplest solution would be to arrange for the source dataset to have simple column names (this is what I would do).

A more complex solution would be to substitute simple names on the fly in the expression. Would need a custom property to hold the pairs of substitutions.

are not valid variable names?