gwtgwt-celltable

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


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?


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.