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?
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
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)
[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.