1.注入相关的DataGrid,一定是DataGrid,不要注入DataSource。
@Inject
private DataGrid<ManufacturingTool> toolBorrowDataGrid;
2.获取选中值
//获得DataGrid的选中值
Iterator<ManufacturingTool> iterator = toolBorrowDataGrid.getSelected().iterator();
List<ManufacturingTool> manufacturingTools = new ArrayList<>();
while (iterator.hasNext()){
manufacturingTools.add(iterator.next());
}
//遍历集合
for (ManufacturingTool tool:manufacturingTools) {
System.out.println("[编号:"+tool.getCode()+" 名称:"+tool.getName()+"]");
}
3.控制台输出