Freeze table column

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

Sorry, thereā€™s no way I know of to do this.

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? :smiley:

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

Thanks!

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.

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

Thanks! Iā€™ll see if I can hack something together, and then Iā€™ll update here if I remember :smiley:

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. 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.

Very inventive!

In the InternalFrameOpened event for the tableā€™s window, do something like:

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

[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:

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.

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.

1 Like