Strange Script behavior reordering columns

I got a table with columns

When I transform the Named Query with a script to style the cells...

def transform(self, value, quality, timestamp):
    if quality.isGood() and value is not None:
        output = []

        py_data = system.dataset.toPyDataSet(value)

        for row in py_data:
            newRow = {}
            for col in py_data.getColumnNames():
                cell_value = row[col]

                if cell_value == 1:
                    bgColor = "#FF555588"
                    fontColor = "#ffffff" 
                    display_value = ""
                elif cell_value == 0:
                    bgColor = "#50BE8788"
                    fontColor = "#FFFFFF"
                    display_value = ""
                else:
                    bgColor = ""
                    fontColor = ""
                    display_value = cell_value 

              
                newRow[col] = {
                    "value": display_value,
                    "style": {
                        "backgroundColor": bgColor if bgColor else "transparent",
                        "color": fontColor,
                        "fontWeight": "bold" if bgColor else "normal", 
                        "textAlign": "center",
                        "borderLeft": "1px solid #FFFFFF" if bgColor else "none",  
                        "borderRight": "1px solid #FFFFFF" if bgColor else "none"  
                    }
                }

            output.append(newRow)

        return output
    else:
     
        return value

...the order of the columns change:

No idea why this happen

to fix column order, you should fill in the column property

Ignition uses Jython which is based on Python 2.7. Dictionaries are unordered. You must specify the field names in the table columns.

Also, I recommend that you do not hard-code colors into your code. Use style classes or theme variables. e.g.,

                    bgColor = "--error"
                    fontColor = "--neutral-10" 

and bgColor = "--success" when things are good.

Ah, ok that´s the reason, thanks a lot for the response, have a good weekend!