# Power Tables - Auto Size Columns

**URL:** <https://forum.inductiveautomation.com/t/power-tables-auto-size-columns/28832>\
**Category:** Ignition\
**Created:** [October 4, 2019, 1:56pm UTC](https://forum.inductiveautomation.com/t/power-tables-auto-size-columns/28832 "2019-10-04T13:56:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mellsberry](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mellsberry](https://forum.inductiveautomation.com/u/mellsberry)\
**Post date:** [October 4, 2019, 1:56pm UTC](https://forum.inductiveautomation.com/t/power-tables-auto-size-columns/28832/1 "2019-10-04T13:56:37Z")

</div>

Is there a script / property equivalent to Right Click Header -\> Auto Resize All Columns? This makes all columns as wide as they need to be to fit the data, even if it causes a horizontal scrollbar. This is the desired result, but the only way I know of causing this to occur is manually doing it every time.

The Auto Resize Mode property basically does the same as above, and then scales all columns down to fit the size of the table, forcing there to be no scrollbar. This is not desired, as strings and numbers are getting concatenated.  
The script below is the equivalent of the "Auto Resize Mode" being set to "All Columns"

> [@Power Table Auto Column Size](http://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/2):
>
> from com.jidesoft.grid import TableUtils from javax.swing import JTable table = event.source.parent.getComponent('Power Table').getTable() table.setAutoResizeMode(JTable.AUTO\_RESIZE\_OFF) TableUtils.autoResizeAllColumns(table) First, third, and last lines are most important.

Ignition 7.8.5

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 4, 2019, 2:11pm UTC](https://forum.inductiveautomation.com/t/power-tables-auto-size-columns/28832/2 "2019-10-04T14:11:51Z")

</div>

The script you want is in the same post you linked to. There maybe an easier way to do this, but I have used this with success. For a power table, use this script in the propertyChange event handler and any time the table data changes the columns will resize accordingly.

```auto
if event.propertyName == 'data':
	#This code resizes a wide table with the scroll bar
	from com.jidesoft.grid import TableUtils
	from javax.swing import JTable
	table = system.gui.getParentWindow(event).getComponentForPath('Root Container.TableName').getTable()
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
	TableUtils.autoResizeAllColumns(table)

```

---

<div class="post-metadata">

**Author:** ![mellsberry](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mellsberry](https://forum.inductiveautomation.com/u/mellsberry)\
**Post date:** [October 4, 2019, 2:30pm UTC](https://forum.inductiveautomation.com/t/power-tables-auto-size-columns/28832/3 "2019-10-04T14:30:16Z")

</div>

Thank you! The last line is the part that I needed

---

<div class="post-metadata">

**Author:** ![SKA](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ska/32/29528_2.png) [@SKA](https://forum.inductiveautomation.com/u/SKA)\
**Post date:** [November 17, 2021, 4:15pm UTC](https://forum.inductiveautomation.com/t/power-tables-auto-size-columns/28832/4 "2021-11-17T16:15:21Z")

</div>

> [@dkhayes117](#):
>
> ```python
> if event.propertyName == 'data':
> #This code resizes a wide table with the scroll bar
> from com.jidesoft.grid import TableUtils
> from javax.swing import JTable
> table = system.gui.getParentWindow(event).getComponentForPath('Root Container.TableName').getTable()
> table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
> TableUtils.autoResizeAllColumns(table)
> 
> ```

Thanks, i was looking for a similar function and this worked with almost just a copy paste, only changing the power table name.
