# Freeze table column

**URL:** <https://forum.inductiveautomation.com/t/freeze-table-column/1621>\
**Category:** Archived Topics\
**Created:** [March 10, 2010, 6:10pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621 "2010-03-10T18:10:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [March 10, 2010, 6:10pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/1 "2010-03-10T18:10:22Z")

</div>

Is it possible to freeze a column in a table so that when you scroll to the side the column will stay stationary?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 11, 2010, 4:37pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/2 "2010-03-11T16:37:14Z")

</div>

Sorry, there’s no way I know of to do this.

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [May 23, 2016, 6:12pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/3 "2016-05-23T18:12:49Z")

</div>

Hi!

Obviously this is a very old thread, but do either of you remember or know of any way to stop a column from scrolling now? 😃

I’d like the first column in my table to stay where it is when I scroll right to view more data.

Thanks!

---

<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:** [May 23, 2016, 7:02pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/4 "2016-05-23T19:02:36Z")

</div>

You could do a second table, overlay it on top of the first or position it right to the left of the table, and have that dataset just be the first column?  
Just a thought, not sure of your implementation or datasets.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [May 23, 2016, 11:44pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/5 "2016-05-23T23:44:47Z")

</div>

There’s no way to do this right now but it’s something we could retrofit into the Power Table

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [May 23, 2016, 11:47pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/6 "2016-05-23T23:47:23Z")

</div>

Thanks! I’ll see if I can hack something together, and then I’ll update here if I remember 😃

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [May 26, 2016, 5:38pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/7 "2016-05-26T17:38:16Z")

</div>

> [@MMaynardUSG](#):
>
> You could do a second table, overlay it on top of the first or position it right to the left of the table, and have that dataset just be the first column?

I was able to come up with a solution using this method. Here's how I did it.

I removed the left column from the original table, and added a second table with a dataset comprised only of that column. I positioned it where the left column would have been, so that it almost looks like it is part of the same table. One important step was to remove the vertical scroll bar from the single column table, which I did using [JGJohnson's suggestion here](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=14663&p=53986#p53986). The rest of the steps are only necessary if you need to be able to scroll your table vertically, because the single column table isn't going to automatically scroll with it.

I added a custom property on the main table called "scrollPosition" which is an integer.

Then I added an invisible button and a timer component in the same container as the two tables. The timer has the following properties:  
[ul]Delay = 250  
Initial Delay = 0  
Running? = True  
Step By = 1  
Bound = 2[/ul]  
The Delay can be lowered if scrolling needs to look smoother for your application, or raised if the smoothness doesn't matter

Here is the script on the timer's propertyChange event handler:

[code]if event.propertyName == 'value':  
#Get the current position of the main table's scroll bar.  
mainTable = event.source.parent.getComponent('tblMain')  
scrollBarMain = mainTable.getVerticalScrollBar()

```
#If the position has changed since last check, click the button to synchronize the left column.
if scrollBarMain.getValue() != mainTable.scrollPosition:
	event.source.parent.getComponent('btnScrollSingleColumn').doClick()
	mainTable.scrollPosition = scrollBarMain.getValue()[/code]

```

And here is the script on the button's "actionPerformed" event handler:

[code]#Get the current position of the main table's scroll bar.  
mainTable = event.source.parent.getComponent('tblMain')  
scrollBarMain= mainTable.getVerticalScrollBar()

#Set the single column table's scroll bar to match the main table.  
singleColumnTable = event.source.parent.getComponent('tblSingleColumn')  
scrollBarSingleColumn = singleColumnTable.getVerticalScrollBar()  
scrollBarSingleColumn.setValue(scrollBarMain.getValue())[/code]

I ended up using a timer for this because I couldn't figure out a way to trigger on the event of the scroll position changing. If I had that trigger/event, it would have been a lot cleaner, I think.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [May 26, 2016, 11:57pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/8 "2016-05-26T23:57:16Z")

</div>

Very inventive!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 27, 2016, 2:00am UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/9 "2016-05-27T02:00:34Z")

</div>

In the InternalFrameOpened event for the table’s window, do something like:

```auto
tbl=event.source.rootContainer.getComponent('MyTable2')
dev myScrollEvent(event):
  # your sync stuff here
tbl.viewport.addChangeListener(myScrollEvent)

```

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [May 27, 2016, 1:02pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/10 "2016-05-27T13:02:10Z")

</div>

[quote=“DougSN”]

I ended up using a timer for this because I couldn’t figure out a way to trigger on the event of the scroll position changing. If I had that trigger/event, it would have been a lot cleaner, I think.[/quote]

In my case the same scroll bar is scrolling both tables because I set the second table to use the same Column Model as the first.

Try this:

```auto
singleColumnTable.table.setColumnModel(mainTable.table.getColumnModel())
```

EDIT: This works for horizontal scroll bars and column widths but does not work for vertical scroll bars. Nevermind.

---

<div class="post-metadata">

**Author:** ![DougSN](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DougSN](https://forum.inductiveautomation.com/u/DougSN)\
**Post date:** [May 27, 2016, 7:03pm UTC](https://forum.inductiveautomation.com/t/freeze-table-column/1621/11 "2016-05-27T19:03:18Z")

</div>

> [@pturmel](#):
>
> In the InternalFrameOpened event for the table's window,

There's the ticket! I stopped the button and timer from running, then added the below code to the window's InternalFrameOpened event handler.

[code]tbl = system.gui.getParentWindow(event).getComponentForPath('Root Container.MainContainer.tblMain')

def myScrollEvent(event = event, mainTable = tbl):  
scrollBarMain = mainTable.getVerticalScrollBar()

```
singleColTable = system.gui.getParentWindow(event).getComponentForPath('Root Container.MainContainer.tblSingleCol')
scrollBarSingleCol = singleColTable.getVerticalScrollBar()
scrollBarSingleCol.setValue(scrollBarMain.getValue())

```

tbl.viewport.addChangeListener(myScrollEvent)[/code]

The formatting is a bit different than your post, but it's working now, and it is so much nicer than relying on a timer.
