user800014
user800014

Reputation:

Vaadin Table: load data only on click of button

My table have a big query, so I want to make the user filter some fields before displaying the table data.

It's possible to make the table get the data only on the click of some button? Actually when I load my view the table already get the data, this is made by the PagedTable or the LazyBeanContainer(I'm using Lazy Container to paginate my table)?

Upvotes: 0

Views: 1183

Answers (2)

Matteo N.
Matteo N.

Reputation: 307

At first you can just init the Table

Table table = new Table()

You should then define a container for your table (I suggest you to use BeanItemContainer)

BeanItemContainer<YourObject> container = new BeanItemContainer<YourObject>(YourObject.class);

At last, you should fill the container in the Button.ClickListener

Button button = new Button("Button", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                table.setContainerDataSource(container);
            }
        });

Upvotes: 3

user800014
user800014

Reputation:

My solution was to set generated columns in the creation of my view:

String[] columns = new String[]{"id","myField"}

for(String col : columns) {
  table.addGeneratedColumn(col, new ColumnGenerator() {
    public Object generateCell(Table source, Object itemId, Object columnId) {
      return "";
    }
  });
}

This results in an empty table, but with columns and labels. Then in the button click, I set the container and remove the old columns:

for(String col : columns) {
  table.removeGeneratedColumn(col);
}
table.setContainerDataSource(myContainer);
...

Upvotes: 0

Related Questions