Vertical scrollbar shifts to the top after user clicks on cell at the bottom [message #1806369] |
Wed, 08 May 2019 04:32  |
Eclipse User |
|
|
|
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 #1806552 is a reply to message #1806460] |
Fri, 10 May 2019 06:45   |
Eclipse User |
|
|
|
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 07:13  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.31409 seconds