How to avoid CellList/Table from automatically scrolling to selected item when visible range is changed

StackOverflow https://stackoverflow.com/questions/11792233

  •  24-06-2021
  •  | 
  •  

Question

I was implementing a custom CellTable that has a infinite scroll feature using the CellList showcase example ( http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellList ). However, I found a feature in CellList/Table that is undesirable in this case: changing visible range after clicking an item would cause the List/Table to be automatically scrolled to the selected item.

you can try the showcase example in above to see the exact same behavior. When no item is selected, the infinite scroll works just fine, but when you click an item and then scroll it, it will always jump back to the selected item when the range is changed.

I also found that it only happens when the focus is still on the item, that is, if you select an item and then click somewhere else to lose the focus, it wouldn't happen.

I've been digging around the GWT code and trying to find out how to disable this feature with no success. Did anyone handled this situation before?

Was it helpful?

Solution

As a simple workaround, you can call focus() on some element, to remove the focus from the item (without removing the selection).

In the showcase example, in ShowMorePagerPanel, add e.g.

scrollable.getElement().focus();

at the beginning of the onScroll(ScrollEvent event) method.

OTHER TIPS

I ran into the same problem and couldn't get Chris's answer to solve it, but the following solution worked for me:

in your onScroll(ScrollEvent event) method, add a line similar to the following, assuming yourTable is an instance of something extending AbstractHasData

yourTable.setFocus(false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top