Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGrid in GWT, can't clear it

Tags:

java

datagrid

gwt

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

like image 240
EMM Avatar asked Oct 31 '12 04:10

EMM


1 Answers

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.

like image 118
logan Avatar answered Sep 28 '22 07:09

logan