我点击按钮在GWT中填充DataGrid.它工作正常,但如果我尝试重新填充它,数据将附加到现有表.
我正在使用UI Binder/GWT 2.5来创建DataGrid.
我已经尝试过了:
// My list which gets updated with the response of RPC. Initially it is empty.
List<List<String>> tableRowData = new ArrayList<List<String>>();
grid.setRowCount(0); // Clears all data.
grid.setRowCount(tableRowData.size(), true); // Set the size of the new data.
grid.setRowData(0, tableRowData); // Set the new data.
Populate tableRowData...
Populate data grid // works perfect
Run Code Online (Sandbox Code Playgroud)
另外自GWT 2.1.1起,还有一个新方法setRowData(List)
列表tableRowData的每个元素也是一个字符串列表.是否可以不使用ListDataProvider.不过,这是第一次完美无缺.
任何人都可以指出我错过了什么.
谢谢
管理Cell小部件的最佳方法是使用DataProvider. GWT 的展示有一些详细的示例ListDataProvider,但是只要保证您的列表很小,您应该可以使用简单的示例。
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDisplay(dataGrid);
List<List<String>> newData = ...;
dataProvider.getList().clear();
dataProvider.getList().addAll(newData);
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请查看有关数据提供程序的新 GWT 文档。感谢这篇文章的调整。