# Power Table Fixed Relative Column Size

**URL:** <https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [April 5, 2019, 3:52pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878 "2019-04-05T15:52:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://forum.inductiveautomation.com/u/BillS)\
**Post date:** [April 5, 2019, 3:52pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/1 "2019-04-05T15:52:33Z")

</div>

Hello,

I have a problem with my power table not always applying the width sizing for my columns.

I looked at [this](http://forum.inductiveautomation.com/t/power-table-auto-column-size/15151) post but that is really the opposite of what my problem is. I do have the Auto Row Height, Columns Resizable set and the Auto-Resize Mode is set to Next Column.

I have attempted various settings of the above settings and some made it worse and but none made it better.

I set the widths by running the window in the developer, adjusting the column widths and then stopping the window and saving things. If there is a better way to do this I’d like to know, and know where it is documented (so I know what I missed)!

The following is the contents of the Column Sizing property:

```auto
6	1268	Feature #	0	2147483647	15	100	100	Side	1	2147483647	15	100	100	Robot Type	2	2147483647	15	100	100	Tool Type	3	2147483647	15	300	300	Station	4	2147483647	15	500	500	Modified?	5	2147483647	15	150	150 1	7	1	Feature #	Side	Robot Type	Tool Type	Station	Modified?

```

Which doesn’t really mean much to me.

What is really weird is that it sometimes formats the table correctly if I leave the screen and go back to it.

Thanks for any help.

Bill

---

<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:** [April 5, 2019, 5:30pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/2 "2019-04-05T17:30:10Z")

</div>

Not sure what your ideal setup is, but you might try this code. It will autosize all the columns based on the width of the contents. It works very well for me on wide tables.

```auto
		from com.jidesoft.grid import TableUtils
		from javax.swing import JTable
		table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table3').getTable()
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
		TableUtils.autoResizeAllColumns(table)

```

---

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://forum.inductiveautomation.com/u/BillS)\
**Post date:** [April 5, 2019, 5:47pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/3 "2019-04-05T17:47:34Z")

</div>

Thank you for the suggestion. I think because of the fact that I override the renderer and replace the contents a bit I might be confusing things…

Example: I have a Tool column that contains “A,B,C” and what gets displayed is “Tool 1, Tool 2, Tool 3” this column can dynamically take multiple rows when needed the replacements are derived from another table, I have another column that just displays the refresh icon which is using a custom renderer. Then there is the column that has “N” or “S” which displays as “North” or “South”. And of course my Type column that has “2”, “7”, or “9” which displays as “M2000”, “M710”, or “M900” from another table.

The Tool and Type columns have dynamic drop downs getting data from another table, and the tool drop down allows multiple selections (which I have an outstanding question about) Most of the code is in the other forum post.

So, does the auto width sizing go off of the shorter string or the string returned by configureCell? Also, what does it do when configureCell returns a different renderer like the refresh column?

Thanks again,  
Bill

---

<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:** [April 5, 2019, 6:26pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/4 "2019-04-05T18:26:37Z")

</div>

I didn’t see the link in your original post. I gave some code you already had access to. Try the code in the propertyChange event of the table inside an if statement

```auto
if event.source.propertyName == 'data':
      from com.jidesoft.grid import TableUtils
      from javax.swing import JTable
      table = system.gui.getParentWindow(event).getComponentForPath('RootContainer.Table3').getTable()
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
      TableUtils.autoResizeAllColumns(table)      

```

---

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://forum.inductiveautomation.com/u/BillS)\
**Post date:** [April 5, 2019, 6:43pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/5 "2019-04-05T18:43:01Z")

</div>

That doesn’t do what I want…

The table does not stretch to the full width of the power table, and the Tools field does not get big enough…

BTW: did you know that you do not have to do the getComponentForPath if you are doing the code in the propertyChange for the Power Table? event.source IS the component. Unfortunately even though the dir(event.source) indicates that getTable() is there, it doesn’t work. I used event.source.table and everything works.

```auto
elif event.propertyName == "data":
	from com.jidesoft.grid import TableUtils
	from javax.swing import JTable
	
#	table = event.source.getTable()
	table = event.source.table
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
	TableUtils.autoResizeAllColumns(table, True)
	TableUtils.autoResizeAllRows(table)

```

But like I said, it doesn’t display the way I wanted it to AND doesn’t change the fact that I set sizes then they got changed!

Thank you,  
Bill

---

<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:** [April 5, 2019, 6:52pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/6 "2019-04-05T18:52:06Z")

</div>

You should be able to adjust the columns widths then save it like you said you did and it stay that way, but you would have to set the auto resize mode to off wouldn’t you? You could try an _initialize_ extension function like below. Again auto resize set to off.

```auto
       tbl = self.parent
	
	tbl.setColumnWidth(0,105)
	tbl.setColumnWidth(1,95)
	tbl.setColumnWidth(2,335)
	tbl.setColumnWidth(3,60)
	tbl.setColumnWidth(4,60)
	tbl.setColumnWidth(5,60)
	tbl.setColumnWidth(6,60)
	tbl.setColumnWidth(7,60)
	tbl.setColumnWidth(8,60)
	tbl.setColumnWidth(9,95)

```

---

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [April 28, 2020, 6:41pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/7 "2020-04-28T18:41:36Z")

</div>

I know this post is older, but where are you inserting this script?

---

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://forum.inductiveautomation.com/u/BillS)\
**Post date:** [April 28, 2020, 8:52pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/8 "2020-04-28T20:52:31Z")

</div>

This code goes in scripting for the table. I presently have it being called in the initialize method and on change of “data”…

```auto
if event.propertyName in ( "editor", "componentRunning" ):
	if event.newValue:
		self.setupColumns()

elif event.propertyName == "data":
	if event.newValue != None:
		self.setupColumns()

```

The following is a major hack and isn’t as dynamic as I had hoped. I had to adjust to allow for the width of the scrollbar on the right side.

With a Custom Method defined:

```auto
def setupColumns(self):
	from com.jidesoft.grid import TableUtils
	from javax.swing import JTable
	
	rootContainer = self.parent.parent
	
	data = self.data
	width = self.getWidth()
	pnWidth = int(width * 0.25)
	dsWidth = int(width * 0.5675)
	otWidth = int(width * 0.145)
		
	headers = system.dataset.getColumnHeaders(data)
	colSizes = []
	for header in headers:
		if header == "PartNumber":
			colSizes.append(pnWidth)
		elif header == "Description":
			colSizes.append(dsWidth)
		elif header in ( "Id", "CNCProgram", "InfeedPickGripDistance", "InfeedTiltAngle", "GripperPadSizeT2A", "GripperPadT2B", "WrenchPadSize", "DropDistance", "GripperSizeT1", "CNCGripDistance", "Width", "GripperSizeT2B", "GripperOffsetT2B" ):
			pass
		else:
			colSizes.append(otWidth)
	
	logger.info("ColSizes %s" % (str(colSizes)))
	
	table = self.table
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
	TableUtils.autoResizeAllColumns(table, colSizes, colSizes, True, True, False, True )
	TableUtils.autoResizeAllRows(table)

```

For this particular table, I’m only displaying 3 columns and I want the description to take up most of the screen real estate.

I call this from within the initialize method and the propertyChange method. This works, but not as well as if the darn thing saved my settings the way it used to.

I get flashes of the table with all the columns scrunched to the left side, then it will reformat to the way I want it.

I REALLY wish that the thing could do this automatically based on given percentages that you lay out in the designer.

Anyway, hope this helps somebody.

Bill

---

<div class="post-metadata">

**Author:** ![Michael\_Frantz](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Michael\_Frantz](https://forum.inductiveautomation.com/u/Michael_Frantz)\
**Post date:** [September 29, 2022, 9:33pm UTC](https://forum.inductiveautomation.com/t/power-table-fixed-relative-column-size/23878/9 "2022-09-29T21:33:21Z")

</div>

Copy - Paste - Change the name of the table & BAM!

(Note - Auto resize mode needed to be set to OFF)

NICE! TYVM.
