# Sort the columns of a power table using scripting

**URL:** <https://forum.inductiveautomation.com/t/sort-the-columns-of-a-power-table-using-scripting/44264>\
**Category:** Ignition\
**Created:** [March 9, 2021, 3:10pm UTC](https://forum.inductiveautomation.com/t/sort-the-columns-of-a-power-table-using-scripting/44264 "2021-03-09T15:10:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [March 9, 2021, 3:10pm UTC](https://forum.inductiveautomation.com/t/sort-the-columns-of-a-power-table-using-scripting/44264/1 "2021-03-09T15:10:00Z")

</div>

Hello  
is it possible to sort the columns of a power table using scripting?  
thanks you

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 9, 2021, 5:53pm UTC](https://forum.inductiveautomation.com/t/sort-the-columns-of-a-power-table-using-scripting/44264/2 "2021-03-09T17:53:23Z")

</div>

Do you want to apply the sort in a way that the user can add/remove?

> [@Power Table Sort Script](http://forum.inductiveautomation.com/t/power-table-sort-script/15524):
>
> For those of you who would like to know how to trigger a Power Table to sort via script, here is how you do it: table = event.source.parent.getComponent(‘Table’) gTable = table.getTable() gTable.setAutoCreateRowSorter(True) gTable.getRowSorter().toggleSortOrder(0) # the 0 (zero) sets which column to sort on

Or do you just want to pre-sort the data, in which case all you need is to invoke `system.dataset.sort` or the `sortDataset` expression function: [sortDataset - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/sortDataset)

---

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [March 10, 2021, 8:43am UTC](https://forum.inductiveautomation.com/t/sort-the-columns-of-a-power-table-using-scripting/44264/3 "2021-03-10T08:43:59Z")

</div>

thanks for the answer Paul. I am trying to sort the order of the columns, not the rows,  
I can do it manually by dragging with the mouse, but I have a table whose data is associated with a chart data, said data when updated the order of the columns is reset, and I am looking for some way to do it with scripting

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 10, 2021, 3:24pm UTC](https://forum.inductiveautomation.com/t/sort-the-columns-of-a-power-table-using-scripting/44264/4 "2021-03-10T15:24:14Z")

</div>

Despite the name, I think [`system.dataset.filterColumns`](https://docs.inductiveautomation.com/display/DOC81/system.dataset.filterColumns) would work for this? If you supply all your column names, but in the correct order, they should be returned in that same order.

I do wonder whether it would be easier to rearrange the columns upstream in wherever you’re retrieving this information from, but this should certainly work.
