# Strange Script behavior reordering columns

**URL:** <https://forum.inductiveautomation.com/t/strange-script-behavior-reordering-columns/91193>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 31, 2024, 12:33pm UTC](https://forum.inductiveautomation.com/t/strange-script-behavior-reordering-columns/91193 "2024-05-31T12:33:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 31, 2024, 12:33pm UTC](https://forum.inductiveautomation.com/t/strange-script-behavior-reordering-columns/91193/1 "2024-05-31T12:33:24Z")

</div>

I got a table with columns

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/5/b55eba68316bff05876f930da28156a3dc9f31c8.png)

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

```python
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:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/06c88fe31d1a13638eb4fe6f75fe24725399bcb5.png)

No idea why this happen

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 31, 2024, 12:48pm UTC](https://forum.inductiveautomation.com/t/strange-script-behavior-reordering-columns/91193/2 "2024-05-31T12:48:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 31, 2024, 12:58pm UTC](https://forum.inductiveautomation.com/t/strange-script-behavior-reordering-columns/91193/3 "2024-05-31T12:58:09Z")

</div>

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

 ![Table field](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/b/7b409527ba704d4cc468b93014b5c0bb68a3b651.png)

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

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

```

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

> **[Perspective Built-In Themes | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/perspective-built-in-themes#built-in-theme-colors)**
>
> Themes

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 31, 2024, 12:59pm UTC](https://forum.inductiveautomation.com/t/strange-script-behavior-reordering-columns/91193/4 "2024-05-31T12:59:23Z")

</div>

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