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

人走茶凉 提交于 2019-12-07 07:09:52

问题


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?


回答1:


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.




回答2:


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);


来源:https://stackoverflow.com/questions/11792233/how-to-avoid-celllist-table-from-automatically-scrolling-to-selected-item-when-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!