Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Vertical scrollbar shifts to the top after user clicks on cell at the bottom(Vertical scrollbar shifts to the top after user clicks on cell at the bottom)
Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806369] Wed, 08 May 2019 08:32 Go to next message
Sharmila Naik is currently offline Sharmila NaikFriend
Messages: 6
Registered: May 2019
Junior Member
HI,

We are using NatTable to display the formsheet data. Our NatTable contains more that 30 columns. Also the rows gets added dynamically to the table.
Since the NatTable with large data does not fit in the screen, it displays both horizontal and vertical scrollbars.
The issue we are facing is, when user double clicks on some cell at the bottom (it opens up some dialog as per our requirement) , the cell gets selected but the vertical
scrollbar moves to the top.User has to scroll down to find which cell he selected. This is annoying to the user working on huge NatTable data.
Our requirement is when user clicks on any cell in the table, the scroll bar should not move automatically and cell should remain focused.

I am using below code to achieve this.

natTable.refresh();
dataLayer.resetRowHeightConfiguration(false);

if (col < 0 || row < 0) {
gif.viewportLayer.moveCellPositionIntoViewport(0, 0);
} else {
CellItem ci = (CellItem) gif.bodyDataProvider.getDataValue(selectionCol, selectionRow);
CellItem mergeParent = null;
if (ci.getMergeParent() != null) {
mergeParent = (CellItem) gif.bodyDataProvider.getDataValue(ci.getMergeParent().x, ci.getMergeParent().y);
row = ci.getMergeParent().y;
}
gif.viewportLayer.moveCellPositionIntoViewport(col, row);
int positionInViewport = gif.viewportLayer.getRowPositionByIndex(row);
while (positionInViewport > 1 && row < gif.bodyDataProvider.getRowCount() - 1) {
row++;
positionInViewport--;
}
gif.viewportLayer.moveCellPositionIntoViewport(col, row);
if (ci.getMergeParent() != null) {
gif.selLayer.setSelectedCell(mergeParent.getColumn(), mergeParent.getRow());
} else {
gif.selLayer.setSelectedCell(selectionCol, selectionRow);
}
if(!gif.natTable.isDisposed())
gif.natTable.redraw();
}

Can you please help me to understand if I am missing anything here.

Thanks,
Sharmila
Re: Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806404 is a reply to message #1806369] Wed, 08 May 2019 14:24 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I have no idea what you want to achieve with that code. But NatTable#refresh() causes a complete reset of states and therefore scrolls to top. There are configurations for opening editors in a dialog and you should also be able to configure that editors should be opened on double click and not single clicks.

As I don't understand your code and what you want to achieve, there is not much I can do.
Re: Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806458 is a reply to message #1806404] Thu, 09 May 2019 11:25 Go to previous messageGo to next message
Sharmila Naik is currently offline Sharmila NaikFriend
Messages: 6
Registered: May 2019
Junior Member
Dirk,
Thanks for your reply.
I have below doubts.

1) Does Nattable.redraw() call internally calls refresh?

2) Does call to ViewportLayer. moveCellPositionIntoViewport() method causes scrollbar to adjust its position so that the that specific row is visible in view port?

3) ViewportLayer.getRowPositionByIndex() method returns the position of the input row. Does this position depend upon resolution of the screen?

Thanks,
Sharmila
Re: Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806460 is a reply to message #1806458] Thu, 09 May 2019 11:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
1) Does Nattable.redraw() call internally calls refresh?

No that should only repaint without changes in the structures.

Quote:
Does call to ViewportLayer. moveCellPositionIntoViewport() method causes scrollbar to adjust its position so that the that specific row is visible in view port?

Actually it is the other way round. The scrollbar is adjusted FOR the visible rows in the viewport. But that is quite the same, so yes.

Quote:
ViewportLayer.getRowPositionByIndex() method returns the position of the input row. Does this position depend upon resolution of the screen?

Well, first it only returns the position of the input row if the row with the given index is visible in the viewport. And it should not be dependent on the screen resolution. Actually there is some code that handles the scaling internally.
Re: Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806552 is a reply to message #1806460] Fri, 10 May 2019 10:45 Go to previous messageGo to next message
Sharmila Naik is currently offline Sharmila NaikFriend
Messages: 6
Registered: May 2019
Junior Member
Hi Dirk,
Thak you for your reply.

I removed unwanted refresh calls from my code. But, I am still facing issue of scrollbar jumping upward (by 2-3 rows).I will try to explain my code.

Below is the method we have written which will set focus on the selected cell and also adjust the scrollbar shift. On double click action listener we are calling this method.

public void moveCellToTop(int col, int row) {
int selectionCol = col;
int selectionRow = row;
if (col < 0 || row < 0) {
gif.viewportLayer.moveCellPositionIntoViewport(0, 0);
}
else
{
gif.viewportLayer.moveCellPositionIntoViewport(col, row);
int positionInViewport = gif.viewportLayer.getRowPositionByIndex(row);
while (positionInViewport > 1 && row < gif.bodyDataProvider.getRowCount() - 1) {
row++;
positionInViewport--;
}
gif.viewportLayer.moveCellPositionIntoViewport(col, row);
gif.selLayer.setSelectedCell(selectionCol, selectionRow);
if(!gif.natTable.isDisposed())
gif.natTable.redraw();
}
}

When I click on the cell, the dialog pops up but the scrollbar jumps a bit (by 2-3 rows) in upward direction. Hence user has to scroll down manually till the selected cell.
Which is not desirable behaviour for the customer.

From my understanding, method "viewportLayer.moveCellPositionIntoViewport" decided how much scrollbar should shift itself.
So if input parameters to the method are col=5, row=7 then , scrollbar should adjust itself in such a way that the 7th row should be visible to the user.
If my understanding is correct, the method is not behaving correctly. Am I missing anything here?

Also to be noted, the issue is not consistently reproduced. And most of the time on the first double click the issue occurs. When user closes the dialog and
double clicks second time, the scrollbar remains steady.

Can you please provide your valuable inputs on this?

Thanks,
Sharmila
Re: Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806560 is a reply to message #1806552] Fri, 10 May 2019 11:13 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I think there are several misunderstandings on your side. Those methods work pretty well if they are understood correctly. And I still don't understand why you need such code with in-depth NatTable know how.

1. Why do you need such a code? moveCellPositionIntoViewport() moves cells into the viewport that are currently not visible. How can a user click on a cell that is not in the viewport? That doesn't make sense to me.
2. moveCellPositionIntoViewport() takes as parameter positions that are based on the scrollable layer, in your case the SelectionLayer I guess. Otherwise the method wouldn't make sense. Are you sure the position parameters you pass are related to the SelectionLayer?.
3. If you want to scroll the selected cell to the top, you need to scroll via setOriginXxx methods where you have to use x/y coordinates based on the scrollable layer

Whatever you are trying to achieve with your code (still don't get it), I think it is the wrong way to do this. I would have implemented an action that triggers a SelectCellCommand and then an EditSelectionCommand and would have registered a custom editor as DialogEditor. Then you only need to use the default mechanisms in NatTable.
Previous Topic:Ad a overlay such as a "glaspane" over the whole table
Next Topic:Prevent sort column
Goto Forum:
  


Current Time: Tue Apr 23 12:33:02 GMT 2024

Powered by FUDForum. Page generated in 0.04766 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top