GWT Cell Table单击新行会给出以前选定行的值
在GWT2.6 CellTable中,我编写了一个单击事件来执行一些操作。单击CellTable行时无法获得正确的行索引;只有双击事件才能正确返回该行GWT Cell Table单击新行会给出以前选定行的值,gwt,Gwt,在GWT2.6 CellTable中,我编写了一个单击事件来执行一些操作。单击CellTable行时无法获得正确的行索引;只有双击事件才能正确返回该行 final SingleSelectionModel<PatientDTO> selectionModel = new SingleSelectionModel<PatientDTO>(); patientsTable.setSelectionModel(selectionModel); patients
final SingleSelectionModel<PatientDTO> selectionModel =
new SingleSelectionModel<PatientDTO>();
patientsTable.setSelectionModel(selectionModel);
patientsTable.addDomHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
{
PatientDTO selected = selectionModel.getSelectedObject();
if (selected != null)
{
RootLayoutPanel.get().clear();
RootLayoutPanel.get().add(new PatientPanel(selected));
}
}
}, ClickEvent.getType());
final SingleSelectionModel selectionModel=
新的SingleSelectionModel();
patientsTable.setSelectionModel(selectionModel);
patientsTable.addDomHandler(新的ClickHandler()
{
@凌驾
公共作废一次点击(点击事件)
{
PatientTo selected=selectionModel.getSelectedObject();
如果(已选择!=null)
{
RootLayoutPanel.get().clear();
RootLayoutPanel.get().add(新PatientPanel(已选择));
}
}
},ClickEvent.getType());
使用SingleSelectionModel
或MultiSelectionModel
并在其上添加SelectionChangeHandler
,当在CellTable中更改选择时将触发该处理程序
示例代码:
final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
//final MultiSelectionModel<Contact> selectionModel = new MultiSelectionModel<Contact>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
Set<Contact> selected = selectionModel.getSelectedSet();
if (selected != null) {
for (Contact contact : selected) {
System.out.println("You selected: " + contact.name);
}
}
}
});
我使用了SingleSelectionModel,现在它会打开新单击的行,但它不会首先选择(我想先单击选择,然后单击同一行执行操作,否则单击其他行会选择其他行)。
table.addCellPreviewHandler(new Handler<Contact>() {
@Override
public void onCellPreview(CellPreviewEvent<Contact> event) {
int row = event.getIndex();
int column = event.getColumn();
if ("focus".equals(event.getNativeEvent().getType())) {
//..
}
if ("blur".equals(event.getNativeEvent().getType())) {
//...
}
if ("mousedown".equals(event.getNativeEvent().getType())) {
//..
}
if ("mouseover".equals(event.getNativeEvent().getType())) {
//..
}
}
});