1

我有一个 DataGrid,我想在单击它时获取选定的行:我想获取它的内容和它的索引。I have some sort of a form under the DataGrid, and when one row is selected, the form will be filled with the data in the selected row above! 然后,当我单击一个按钮时,应显示一个对话框,其中包含所选行中的数据!

我已经搜索过,但没有关于如何做到这一点的明确解释。谢谢

4

2 回答 2

3

Gwt DataGrid 的 API 中,有一个关于如何使用 GWT DataGrid 和selection model.

在那个例子中:

// Add a selection model to handle user selection. 


final SingleSelectionModel<Contact> selectionModel =
                                           new SingleSelectionModel<Contact();
table.setSelectionModel(selectionModel); 
selectionModel. addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
 public void onSelectionChange( SelectionChangeEvent event) { 
 Contact selected = selectionModel. getSelectedObject();
 if (selected != null) {
 Window.alert("You selected: " + selected.name); }
 } });
于 2013-04-07T16:35:42.567 回答
3
DataGrid table = new DataGrid();

final SingleSelectionModel<Contact> selectionModel =
                                           new SingleSelectionModel<Contact>();
table.setSelectionModel(selectionModel); 

Button clickBtn = new Button("Click Button");
clickBtn.addClickHandler(new ClickHandler(){
Contact selectedContact = ((SingleSelectionModel)table.getSelectionModel()).getSelectedRecord();
setDataInForm(selectedContact);
});
于 2013-04-07T16:54:34.180 回答