Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

how to remove a row from the table

meghana vemuri
1 decade ago Apr 17, 2010 5:37am

i added checkboxes to the table and a delete button to the layout.now the required items selected through checkbox should be deleted when i press delete button.i am getting all the item ids and written statements to read the checkbox and display whether it is true (checked).now i am not able to get that particular item id of a particular row which is checked .the moment the id of the checked item is got that particular item should be deleted.can anyone please help me how to get the item id of a particular selected row?can you please reply me soon?

Last updated on Apr, 17th 2010
Henri Muurimaa
1 decade ago Apr 17, 2010 6:43am

You need to iterate all items in the table and check the corresponding checkbox state. A quick example:

public class TestcaseApplication extends Application {
	private Table table;

	public void init() {
		setMainWindow(new Window("Test Application"));

		getMainWindow().addComponent(table = new Table());

		table.addContainerProperty("Checkbox", CheckBox.class, null);
		table.addContainerProperty("String", String.class, null);

		for (int i = 0; i < 10; i++) {
			Object id = table.addItem();
			table.getContainerProperty(id, "Checkbox").setValue(new CheckBox());
			table.getContainerProperty(id, "String").setValue("row " + id);

				new Button("Delete checked", new ClickListener() {
					public void buttonClick(ClickEvent event) {
						// Can't delete while iterating the item ID collection,
						// so we store the item ids and delete outside the loop
						List<Object> toDelete = new ArrayList<Object>();

						for (Object id : table.getItemIds()) {
							// Get the checkbox of this item (row)
							CheckBox checkBox = (CheckBox) table
									.getContainerProperty(id, "Checkbox")

							if (checkBox.booleanValue()) {

						// Perform the deletions
						for (Object id : toDelete) {

								"Removed " + toDelete.size() + " rows");
jose Perez Paramo
7 years ago Jun 25, 2015 5:40pm