# Auto center in power table

**URL:** <https://forum.inductiveautomation.com/t/auto-center-in-power-table/14091>\
**Category:** Ignition\
**Created:** [April 20, 2017, 12:23pm UTC](https://forum.inductiveautomation.com/t/auto-center-in-power-table/14091 "2017-04-20T12:23:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ddugas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ddugas/32/14144_2.png) [@Ddugas](https://forum.inductiveautomation.com/u/Ddugas)\
**Post date:** [April 20, 2017, 12:23pm UTC](https://forum.inductiveautomation.com/t/auto-center-in-power-table/14091/1 "2017-04-20T12:23:52Z")

</div>

Here is my problem

- i created a powertable with a few dropdown beside the table , these dropdown are used to select different option that the user can select to show a different query in the powertable.  
to generate the query i use a python script that i inserted on a button that i called “search”.  
so when the user press search depending on the selection he made on the dropdown it will generate a different query in his power table.  
the problem i have is that the column that the query generate are not allway the same .  
col name ex 1: Date , day ,shift , piece per bundle  
col name ex 2: Date , day ,shift , pellets per bag  
So when the 4th column name change , the whole column text auto align to left because it automaticaly fall into “auto align”, i can change them in table customizer but as soon as the name change he forget the previous alignment and swith to auto and the whole column aligne to left .

i wish this is clean enough for you guys im french as main language and i tried to be as clear as possible !  
Thx 😉

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [April 20, 2017, 12:47pm UTC](https://forum.inductiveautomation.com/t/auto-center-in-power-table/14091/2 "2017-04-20T12:47:53Z")

</div>

You can set the width of the columns in code.  
After your code to change the data source, run this for any columns you need to resize

tbl = event.source.parent.getComponent(‘tblSearch’)  
tbl.setColumnWidth(0, 15)  
tbl.setColumnWidth(1, 25)  
tbl.setColumnWidth(2, 55)  
etc.

[https://docs.inductiveautomation.com/display/DOC79/Power+Table](https://docs.inductiveautomation.com/display/DOC79/Power+Table)

---

<div class="post-metadata">

**Author:** ![Ddugas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ddugas/32/14144_2.png) [@Ddugas](https://forum.inductiveautomation.com/u/Ddugas)\
**Post date:** [April 20, 2017, 12:59pm UTC](https://forum.inductiveautomation.com/t/auto-center-in-power-table/14091/3 "2017-04-20T12:59:03Z")

</div>

> [@MMaynard](#):
>
> setColumnWidth

Thanks for your fast answer !  
I didnt know that but this is not really what i was talking about , its the text in the colomn that i need to be centered.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [April 20, 2017, 1:25pm UTC](https://forum.inductiveautomation.com/t/auto-center-in-power-table/14091/4 "2017-04-20T13:25:21Z")

</div>

Ahh ok.  
Under Scripting on the Power Table, go to the configureCell extension function.  
Then enable it and add something like this for each column you want the text centered.

```
if colIndex==2:
	return {'horizontalAlignment':0}
```
