# Dataset transform script disorder original column position in table component

**URL:** <https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 25, 2023, 8:36am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839 "2023-07-25T08:36:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo\_Fernandez\_Expo](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@Pablo\_Fernandez\_Expo](https://forum.inductiveautomation.com/u/Pablo_Fernandez_Expo)\
**Post date:** [July 25, 2023, 8:36am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/1 "2023-07-25T08:36:27Z")

</div>

Hi all,

I am using a table component with data biding to a named query. When using this biding directly, the data shows as expected. Going 1 step further, I added a script transform to change the cell background color based on its value. After this transform, the data columns are showing in, what it seems to me, random order.

Top table is without transform, bottom table with.

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d86e0e091e9d473daef90c7f6c30a65d354ed49c.jpeg)  
Here you can see the script transform used  
 ![Capture2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8d5bd951f0025d7b0f38e6f24909c5be2d5c727a.jpeg)

Thanks in advance!

---

<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:** [July 25, 2023, 8:42am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/2 "2023-07-25T08:42:30Z")

</div>

you should define columns on your table for consistent ordering

---

<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:** [July 25, 2023, 8:55am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/3 "2023-07-25T08:55:15Z")

</div>

Tips:  
Post formatted code - not pictures of code. (Use the \</\> button.) That way we can copy and edit in our answers instead of typing it all out again.  
Crop screengrabs to relevant portions.

---

<div class="post-metadata">

**Author:** ![Pablo\_Fernandez\_Expo](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@Pablo\_Fernandez\_Expo](https://forum.inductiveautomation.com/u/Pablo_Fernandez_Expo)\
**Post date:** [July 25, 2023, 9:00am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/4 "2023-07-25T09:00:25Z")

</div>

Thanks for the tip,

Here is the code

```auto
	output_json = []
	style_CIP = {"backgroundColor": "#D8BFD8"}
	style_Flush = {"backgroundColor": "	#B0E0E6"}
		
	for row in range(value.getRowCount()):
		row_object = {}
		for col in value.getColumnNames():   
			cell_object={}
			cell_style={}
			cell_object['value']=value.getValueAt(row,col)
			if "material" in col:
				if value.getValueAt(row,col)==0:
					cell_style= style_CIP # between
				elif value.getValueAt(row,col)==1:
					cell_style= style_Flush						
			cell_object['style']=cell_style
			row_object[col]=cell_object				
		output_json.append(row_object)	
	return output_json

```

---

<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:** [July 25, 2023, 9:01am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/5 "2023-07-25T09:01:29Z")

</div>

Your script is transforming the data into JSON which, in Python 2.7, does not preserver ordering.  
As Victor says, you need to define the `field` property of each column in the order to want and that will sort out the problem.

---

<div class="post-metadata">

**Author:** ![Pablo\_Fernandez\_Expo](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@Pablo\_Fernandez\_Expo](https://forum.inductiveautomation.com/u/Pablo_Fernandez_Expo)\
**Post date:** [July 25, 2023, 9:25am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/6 "2023-07-25T09:25:50Z")

</div>

Thanks, that solved the problem!

---

<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:** [July 25, 2023, 10:02am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/7 "2023-07-25T10:02:52Z")

</div>

> [@Transistor](#):
>
> transforming the data into JSON which

Its not json, its just a python array (list) with objects(dicts).  
It just looks like json. Json is data parsed into a specific **string format**. so its a string. This can be decoded back to python (or almost any other langague)  
A lot of people on the forum seem to be confused about this xd

---

<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:** [July 25, 2023, 11:03am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/8 "2023-07-25T11:03:45Z")

</div>

> [@victordcq](#):
>
> A lot of people on the forum seem to be confused about this

Yes, I'm aware of the difference but mustn't have really grasped it properly. As a result I keep forgetting and mixing the terminology. Thanks for the reminder.

---

<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:** [July 25, 2023, 11:09am UTC](https://forum.inductiveautomation.com/t/dataset-transform-script-disorder-original-column-position-in-table-component/76839/9 "2023-07-25T11:09:40Z")

</div>

no worries, its not rly a big deal 😛 its also igntions fault, somewhere in the bindings they give an option to return it as dataset or as "json".

idk if it actualy returns json, it could be internally, but it gets turned into a python object somewhere along the way
