# Sorting and moving tag values in a table

**URL:** <https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862>\
**Category:** Ignition\
**Tags:** database, ignition79, scripting\
**Created:** [September 29, 2023, 6:28pm UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862 "2023-09-29T18:28:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paramjeet\_Birdi](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paramjeet\_Birdi](https://forum.inductiveautomation.com/u/Paramjeet_Birdi)\
**Post date:** [September 29, 2023, 6:28pm UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/1 "2023-09-29T18:28:19Z")

</div>

Hi, I am using Ignition version 7.9.18. I am trying to create a table that will have two columns (Rack Pos, Curing Time) and 21 Rows. I am using a script to create a dataset and want to link my tag values to that dataset. Also need to sort the rows based on who will have lowest curing time value (which goes from 45 min. to zero). I have created a basic script shown below but stuck on how should I add the real time updating tag values instead for strings and how should I sort them. Can somebody help me out please:-

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/919eae76f24728e62aa3029fa1a9eed14c72c028.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 30, 2023, 7:31am UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/2 "2023-09-30T07:31:15Z")

</div>

We don't know anything about your tags, so it pretty hard to tell you how to use them...  
Also, you tagged your post with "database". How are databases relevant here ? you never mentioned this.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 30, 2023, 12:24pm UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/3 "2023-09-30T12:24:03Z")

</div>

As Pascal stated, we'll need a bit more info to better help you out. But this is how I would do it, and perhaps give some inspiration.

* * *

A tag structure to put the curing racks in one area. My exmaple has 5 racks with a description and a cure time value. Also, since tags are global, I added a datast tag to hold our results.

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

Using a Gateway Timer Script:

```python
basePaths = ['[Test]Curing Rack/%d/Description',
             '[Test]Curing Rack/%d/Cure Time'
            ]

# Create the list of tags to read
tagsIn = []
for i in xrange(5): # Number of racks
	tagsIn.extend([tag%(i+1) for tag in basePaths]) 

# Get the tag values
valuesIn = [tag.value for tag in system.tag.readAll(tagsIn)]

headers = ['Rack Pos', 'Curing Time']
# Split the flat value list into a list of lists.
data = [valuesIn[i:i+2] for i in xrange(0, len(valuesIn), 2)]

dataset = system.dataset.toDataSet(headers, data)

# Write the sorted dataset to the tag.
system.tag.write('[Test]Curing Rack/Dataset', system.dataset.sort(dataset, 'Curing Time', False))

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/d/ed141a48a6d1432deef6e1e3c472a56ce87c5ab3.png)

Then, just bind the table to the dataset tag.

---

<div class="post-metadata">

**Author:** ![Paramjeet\_Birdi](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paramjeet\_Birdi](https://forum.inductiveautomation.com/u/Paramjeet_Birdi)\
**Post date:** [September 30, 2023, 9:54pm UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/4 "2023-09-30T21:54:39Z")

</div>

Hi Pascal, I haven't created the tags yet but I will try Jordan's method now. The plant where I am working at has a database called Igear. I was thinking of doing the table and sorting in the database and then just doing a query in ignition to display the table. Not sure if this method will even work. I am pretty new to Ignition so please bear with me.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Paramjeet\_Birdi](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paramjeet\_Birdi](https://forum.inductiveautomation.com/u/Paramjeet_Birdi)\
**Post date:** [September 30, 2023, 9:57pm UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/5 "2023-09-30T21:57:02Z")

</div>

Hi Jordan,  
Thanks for your help. I will try your method with tags and script and hopefully I will make it work.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 1, 2023, 6:02am UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/6 "2023-10-01T06:02:29Z")

</div>

It seems to me you're not sure about where your data should go (tags, database...)  
What's the source of the data ? Does it come from PLCs ? From an API ?

If you can tell us a bit more, we can help you chose between tags and database.

---

<div class="post-metadata">

**Author:** ![Paramjeet\_Birdi](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paramjeet\_Birdi](https://forum.inductiveautomation.com/u/Paramjeet_Birdi)\
**Post date:** [October 1, 2023, 6:51pm UTC](https://forum.inductiveautomation.com/t/sorting-and-moving-tag-values-in-a-table/79862/7 "2023-10-01T18:51:16Z")

</div>

The data comes from the PLC (Allen Bradley). The tags in the PLC are integers global tags.
