我正在使用GWT 2.4,Hibernate和MysQL 我创建了一个单元格表,当我单击一个单元格时,我想显示该特定单元格中的数据/值
提前致谢
答案 0 :(得分:0)
DataProvider
使用SingleSelectionModel
和cellTable
:
private final ListDataProvider<SomeClass> dataProvider = new ListDataProvider<SomeClass>();
private final SingleSelectionModel<SomeClass> selectionModel = new SingleSelectionModel<SomeClass>();
//then
table.setSelectionModel(selectionModel);
dataProvider.addDataDisplay(table);
以下是如何获取所选对象的信息:
showDataValueOfCellBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
SomeClass selected = selectionModel.getSelectedObject();
Window.alert (selected.getValue());
}
});
答案 1 :(得分:0)
@override
public Widget onInitialize(){
CellTable grid = new CellTable<Bean>();
grid.setWidth("100%",true);
setColumns(grid);
}
private void setColumns(CellTable grid){
Column<Bean, String> firstNameColumn = new Column<Bean, String>(
new EditTextCell()) {
@Override
public String getValue(Bean object) {
return object.getFirstName();
}
};
firstNameColumn.setSortable(true);
grid.addColumn(firstNameColumn, "First Name");
Column<Bean, String> imageColumn = new Column<Bean, String>(
new ClikableTextCell()) {
@Override
public String getValue(Bean object) {
return "clickhere";
}
};
imageColumn.setSortable(true);
grid.addColumn(imageColumn, "Add Information");
firstNameColumn.setFieldUpdater(new FieldUpdater<Bean, String>() {
public void update(int index, Bean object, String value) {
Window.alert("You clicked " + object.getFullName());
}
});
cellTable.setColumnWidth(firstNameColumn, 20, Unit.PCT);
}