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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Table how to clear data
How do I clear all data from the table and put new data in it..
Just like a new table.. withouth column and data row.. ?
Please help :(
table.setContainerDataSource(new BeanItemContainer<Object>(Object.class));
Hello sir..
I havent use data source..
my goal is I want to make the table be fresh again..
So it means that the header and data should be removed..
I tried table.clear();
but when the new data comes.. the previous header and data will be merge to the new data.. instead it should be replaced with the new data...
Class.forName(TableexporterUI.JDBC_SERVER);
System.out.println("Connecting to databse...");
conn = DriverManager.getConnection(DB_URL,"root","");
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = textField.getValue();
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
for(int i=1; i<=rsmd.getColumnCount(); i++) {
table.addContainerProperty(rsmd.getColumnName(i), String.class, null);
}
int count = 0;
while(rs.next()) {
count++;
Object tableData[] = new Object[rsmd.getColumnCount()];
for(int i=0; i<rsmd.getColumnCount(); i++) {
tableData[i] = rs.getString(rsmd.getColumnName(i+1));
}
table.addItem(tableData, new Integer(count) );
}
I think, that the easiest way is:
table.removeAllItems();
List props = new ArrayList(getContainerPropertyIds());
for(Object prop: props){
table.removeContainerProperty(prop);
}
Wow.. thanks for your help sir.. :)
It help me ... :) .. thank you..
table.removeAllItems(); //removes all data in the table except column headers/titles