David Tinker
David Tinker

Reputation: 9634

How to add a row to a CellTable?

I am using a CellTable with "on grid" editing in my application. Editing existing rows works fine. However I now am struggling to support adding a new row to the bottom of the table in a non-hacky way. What is the best way to do this?

My (hacky) solution:

My code that responds to RangeChangeEvent's to load the data keeps a reference to the last page set on the table. To add a new row I add an object to the end of this list and do table.setRowData with the expanded list. I have to make sure I keep within the page size of the table by removing an element from the list as well. There are lots of issues with this when on the last page of the data set.

I would have thought that this would be a common use-case.

Maybe I need to create my own intermediate collection of rows and page data from that + only fetch new rows from the server when really needed? This will still have the issue with changing the grid page size just to add a new row.

Upvotes: 2

Views: 4191

Answers (2)

iavci
iavci

Reputation: 209

This is how I achieve doing it.

CellTable<Style> table = new CellTable<Style>();
List<Style> t = new ArrayList<Style>();
//add some data to List "t" and populate the table. 
table.setRowCount(t.size(), true);
table.setRowData(0, t);
//everytime you want to add row, first add data to List "t" and populate the table again.

Upvotes: 3

AlexR
AlexR

Reputation: 115328

I am not familiar with GWT but this probably it is AbstractHasData.setRowData()

http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/cellview/client/AbstractHasData.html#setRowData%28int,%20java.util.List%29

(class AbstractHasData extends AbstractHasData).

Upvotes: 0

Related Questions