I am populating a DataGrid in GWT on a button click. It is working fine but if I try to re-populate it, the data gets appended to the existing table.
I am using UI Binder/GWT 2.5 to create DataGrid.
I have already tried this:
// 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
Also since GWT 2.1.1, there is a new method setRowData(List)
Each element of the list tableRowData is again a list of strings. Is it even possible without
using ListDataProvider. For first time it works perfect, though.
Can anyone please point out what I am missing.
Thanks
The best way to manage Cell
widgets is using a DataProvider
. GWT's showcase has some elaborate examples, but you should be fine with a simple ListDataProvider
as long as your list is guaranteed to be small.
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDisplay(dataGrid);
List<List<String>> newData = ...;
dataProvider.getList().clear();
dataProvider.getList().addAll(newData);
For more information, check out the new GWT documentation about data providers. Thanks to this post for tweaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With