Diaz Pradiananto
Diaz Pradiananto

Reputation: 457

Vaadin : Filtering output on the table

im new in java component base framework, especially vaadin. before use this framework, im using struts 2.

so when i want to query some table, i have a search box, contains many textfield. when user click Search Button, then the parameters from the texfield will be sent into my hibernate directly using http post.

my question, how to filter the output using vaadin?

Upvotes: 3

Views: 4671

Answers (3)

Diego Quirós
Diego Quirós

Reputation: 977

This is my solution to filter rows using a text that user inputs using textfield:

textField.addTextChangeListener(new TextChangeListener() {

            @Override
            public void textChange(TextChangeEvent event) {
                Filterable filter= (Filterable) (table.getContainerDataSource());
                filter.removeAllContainerFilters();

                String filterString = event.getText();
                if (filterString.length() > 0) {
                    filter.addContainerFilter(new Like("columnName", "%"+filterString +"%"));
                }

            }
        });

I hope code is selfexplanatory.

Upvotes: 0

user3865165
user3865165

Reputation: 1

filterString = checkBox.getValue().toString();
Filterable f = (Filterable)(table.getContainerDataSource());
        if(filters==null)
            filters=new TreeMap<Object, SimpleStringFilter>();
        SimpleStringFilter filter=filters.remove(propertyId);
            if (filter != null){
                f.removeContainerFilter(filter);
            }
            filter = new SimpleStringFilter(propertyId, filterString, ignoreCase, onlyMatchPrefix);
        filters.put(propertyId, filter);
        f.addContainerFilter(filter);

Upvotes: 0

eugen-fried
eugen-fried

Reputation: 2173

Just update your BeanContainer with new data. Here is an example of my code

public void refreshTableData() {
    getBeanContainer().removeAllItems();
    List<Customer> customers = customerDao.getByCustomerFilter(getCustomerFilterForm().getFilterItem().getBean());
    getBeanContainer().addAll(customers);
}

Where CustomerFilter is a bean that has all the search criteria data, that I fill it within a form earlier (e.g with comboboxes), and beanContainer is my table container data source.

Upvotes: 3

Related Questions