GWT CellList 单击以切换选择(多项选择)
我想设置一个 CellList,以便单击一行将切换选择。这样无需按住 ctrl 键即可选择多行。
我需要更改什么才能使其正常工作?
class ToggleEventTranslator<T> implements DefaultSelectionEventManager.EventTranslator<T> {
@Override
public boolean clearCurrentSelection(final CellPreviewEvent<T> event) {
return false;
}
@Override
public SelectAction translateSelectionEvent(final CellPreviewEvent<T> event) {
return SelectAction.TOGGLE;
}
}
MultiSelectionModel<ObjProxy> multiSelectionModel = new MultiSelectionModel<ObjProxy>();
ocjCellList.setSelectionModel(multiSelectionModel, DefaultSelectionEventManager
.<ObjProxy> createCustomManager(new ToggleEventTranslator<ObjProxy>()));
I'd like to setup a CellList so that clicking a row will toggle the selection. Such that multiple rows can be selected with out the need for holding the ctrl key.
What do I need to change to get it working?
class ToggleEventTranslator<T> implements DefaultSelectionEventManager.EventTranslator<T> {
@Override
public boolean clearCurrentSelection(final CellPreviewEvent<T> event) {
return false;
}
@Override
public SelectAction translateSelectionEvent(final CellPreviewEvent<T> event) {
return SelectAction.TOGGLE;
}
}
MultiSelectionModel<ObjProxy> multiSelectionModel = new MultiSelectionModel<ObjProxy>();
ocjCellList.setSelectionModel(multiSelectionModel, DefaultSelectionEventManager
.<ObjProxy> createCustomManager(new ToggleEventTranslator<ObjProxy>()));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“无论您是否添加复选框列,您都必须添加单元格预览定义处理程序的最简单方法是使用 DefaultSelectionEventManager,可以使用 复选框管理器与复选框列组合,或创建自定义事件(您可以将点击事件映射到 切换操作)。
您可以在 GWT Showcase;它使用带有两个参数的
setSelectionModel
重载来同时添加CellPreviewEvent.Handler
。”(来源 这个答案)
"Whether you add a checkbox column or not, you'll have to add a cell preview handler. The easiest way to define one is to use DefaultSelectionEventManager, either using a checkbox manager in combination with a checkbox column, or creating a custom one (you'd map a click event into a toggle action).
You can see it used, the checkbox variant, in the GWT Showcase; it uses the
setSelectionModel
overload with two arguments to add theCellPreviewEvent.Handler
at the same time."(Credit to this answer)