Remove all rows from FlexTable

2,373 views
Skip to first unread message

hezjing

unread,
Oct 2, 2008, 3:55:15 AM10/2/08
to gwt
Hi

I'm populating a FlexTable using setText(row, column, text).

Here is what I did to clear the entire contents of a FlexTable,

            int count = myFlexTable.getRowCount();
            for (int i = 0; i < count; i++) {
                myFlexTable.removeRow(i);
            }

Is there a more elegant way to clear a FlexTable?

Thank you!


--

Hez

obesga

unread,
Oct 2, 2008, 4:16:19 AM10/2/08
to Google Web Toolkit
myFlexTable.clear()

will remove the widgets on the table, I don't now if this will be
usefull to you

Or simlpy remove the flextable from the parent widget and atach a new
flextable

Oskar

hezjing

unread,
Oct 2, 2008, 5:05:51 AM10/2/08
to Google-We...@googlegroups.com
Hi Oskar

Unfortunately the clear() does not work, the Javadoc explained that clear() removes all widgets from the table, but does not remove other HTML or "text" contents of cells.

--

Hez

Lothar Kimmeringer

unread,
Oct 2, 2008, 5:18:48 AM10/2/08
to Google-We...@googlegroups.com
hezjing schrieb:

> Unfortunately the clear() does not work, the Javadoc explained that
> clear() removes all widgets from the table, but does not remove other
> HTML or "text" contents of cells.

Sounds strange. Can you post a small example what exactly you mean?
Especially what you mean with "other HTML or text". HTML is a widget
and text generally is handled as Label-widget.


Regards, Lothar

hezjing

unread,
Oct 2, 2008, 5:47:47 AM10/2/08
to Google-We...@googlegroups.com
OK, I don't want to pollute this mailing list with my messy codes and so, I thought showing the following callback is sufficient:

    private AsyncCallback<List<Customer>> callback = new AsyncCallback<List<Customer>>() {
        public void onFailure(Throwable caught) {
        }
        public void onSuccess(List<Customer> customers) {
            customersFlexTable.clear();
            int row = 0;
            for (Customer customer : customers) {
                customersFlexTable.setText(row, 0, customer.getFirstName());
                customersFlexTable.setText(row, 1, customer.getLastName());
                row++;
            }
        }
    };

When a use selects a customer type from a ListBox, the ClickListener will make a RPC call and return a list of customers.
I want to clear the existing customerFlexTable, and show only the data returned from the RPC call.

The problem now is that customersFlexTable.clear() seems not clearing the existing data.
--

Hez

Lothar Kimmeringer

unread,
Oct 2, 2008, 5:53:47 AM10/2/08
to Google-We...@googlegroups.com
hezjing schrieb:

> OK, I don't want to pollute this mailing list with my messy codes and
> so, I thought showing the following callback is sufficient:
>
> customersFlexTable.setText(row, 0, customer.getFirstName());
> customersFlexTable.setText(row, 1, customer.getLastName());
>
> When a use selects a customer type from a ListBox, the ClickListener
> will make a RPC call and return a list of customers.
> I want to clear the existing customerFlexTable, and show only the data
> returned from the RPC call.
>
> The problem now is that customersFlexTable.clear() seems not clearing
> the existing data.

I don't know if this a bug in FlexTable (I assume the developers
will read here as well), but the fastest solution would be to use

customersFlexTable.setText(row, 0, new Label(customer.getFirstName()));
customersFlexTable.setText(row, 1, new Label(customer.getLastName()));


Regards, Lothar

hezjing

unread,
Oct 2, 2008, 6:04:58 AM10/2/08
to Google-We...@googlegroups.com
Hi Lothar

Yes, it works when changed to the following,

customersFlexTable.setWidget(row, 0, new Label(customer.getFirstName()));
customersFlexTable.setWidget(row, 1, new Label(customer.getLastName()));



Thank you!

--

Hez

walden

unread,
Oct 2, 2008, 9:20:20 AM10/2/08
to Google Web Toolkit
Yes there is.

myFlexTable = new FlexTable();
// code to plug the new instance in where the old instance used to be

Walden

olivier nouguier

unread,
Oct 2, 2008, 10:27:46 AM10/2/08
to Google-We...@googlegroups.com
Hi,
 IMHO it's also necessary to remove the "old" myFlexTable from is parent ? no ?
--
"Quand le dernier arbre sera abattu, la dernière rivière asséchée, le dernier poisson péché, l'homme va s'apercevoir que l'argent n'est pas comestible"  
     - proverbe indien Cri

Thomas Broyer

unread,
Oct 2, 2008, 10:56:47 AM10/2/08
to Google Web Toolkit

On 2 oct, 09:55, hezjing <hezj...@gmail.com> wrote:
The fastest is to create a new FlexTable to replace the old one (as
proposed by Walden).

If you can't (for whatever reason), then the above code won't work,
you have to count down:
int count = myFlexTable.getRowCount();
while (count > 0) {
myFlexTable.removeRow(0);
}

But let me reiterate: the fastest will be to throw away your current
table and create a new one.

walden

unread,
Oct 2, 2008, 4:06:42 PM10/2/08
to Google Web Toolkit
That depends on the nature of the parent. For example, with a
SimplePanel as parent, you wouldn't.

On Oct 2, 10:27 am, "olivier nouguier" <olivier.nougu...@gmail.com>
wrote:
>      - proverbe indien Cri- Hide quoted text -
>
> - Show quoted text -

Narasimha Aditya Gollapudi

unread,
Jul 2, 2013, 7:14:35 PM7/2/13
to google-we...@googlegroups.com, gwt, hez...@gmail.com
You could use myFlexTable.removeAllRows()
Reply all
Reply to author
Forward
0 new messages