GXT 3 问题:
有谁知道为什么当我选择网格上的任何行时这两个处理程序不会被触发? SelectionModel为GridSelectionModel,设置为单选。
还有什么需要做的声明吗?就这么简单,不是吗。我为 GXT 2.2 添加事件监听器没有问题,但 GXT 3 中有一些更改。这些事件用于检测行选择,不是吗?
SelectionChangedHandler<Summary> gridSelectionChangedHandler =
new SelectionChangedHandler<Summary>() {
public void onSelectionChanged(
SelectionChangedEvent<Summary> event) {
Summary rec = event.getSelection().get(0);
Window.alert("Row = "+ rec.getId());
}
};
SelectionHandler<Summary> gridSelectionHandler =
new SelectionHandler<Summary>() {
public void onSelection(SelectionEvent<Summary> event) {
Summary rec = event.getSelectedItem();
Window.alert("Row = "+ rec.getId());
}
};
public SummaryViewImpl() {
uiBinder.createAndBindUi(this);
this.grid.addSelectionChangedHandler(gridSelectionChangedHandler);
this.grid.addSelectionHandler(gridSelectionHandler);
}
但是,我对 RowClickEvent 没有任何问题,因为以下内容正在触发:
@UiHandler({ "grid" })
void onRowClick(RowClickEvent event){
int row = event.getRowIndex();
Window.alert("Row = "+ row);
}
grid 是 SummaryGrid 的一个实例:
public class SummaryGrid
extends Grid<Summary>{
{
this.sm = new GridSelectionModel<Summary>();
this.sm.setSelectionMode(SelectionMode.SINGLE);
}
blah ... blah ...
public HandlerRegistration addSelectionChangedHandler(SelectionChangedHandler<Summary> handler){
return this.getSelectionModel().addSelectionChangedHandler(handler);
}
public HandlerRegistration addSelectionHandler(SelectionHandler<Summary> handler){
return this.getSelectionModel().addSelectionHandler(handler);
}
blah ... blah ...
}
最佳答案
试试这个grid.getSelectionModel().addSelectionChangedHandler
不确定您是否需要先设置选择模式,但我的工作代码如下:
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.getSelectionModel().addSelectionChangedHandler(new SelectionChangedHandler<Summary>() {
...
}
关于java - GXT 3 : GridSelectionModel SelectionEvent/SelectionChangedEvent not firing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15513785/