我在点击按钮时在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
此外,自GWT 2.1.1起,还有一种新方法setRowData(List)
列表tableRowData的每个元素也是一个字符串列表。甚至可能没有 使用ListDataProvider 。但是,它第一次完美无缺 任何人都可以指出我错过了什么。
由于
答案 0 :(得分:2)
管理Cell
小部件的最佳方法是使用DataProvider
。 GWT的展示有一些elaborate examples,但只要您的列表保证很小,您就可以使用简单的ListDataProvider
。
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDisplay(dataGrid);
List<List<String>> newData = ...;
dataProvider.getList().clear();
dataProvider.getList().addAll(newData);
有关详细信息,请查看新的GWT documentation about data providers。感谢this post进行调整。