Hi.
could anybody give good examples of using filter in table. I need to do something like quick search for my table. All table datasource is taken from database and I want that search filter works with local data, it mean without any query to database. It is possible?
Build table…
List<XXX> list = xxx.getStaffCards();
qqq= new Table() {
@Override
protected String formatPropertyValue(Object rowId, Object colId, Property property) {
if (property.getType() == Date.class) {
SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy hh:mm");
return df.format((Date) property.getValue());
}
return super.formatPropertyValue(rowId, colId, property);
}
};
You can use filters for any Filterable container, such as BeanItemContainer, HierarchicalContainer, IndexedContainer.
Just set your filter(s) via addContainerFilter method and you’re filtered.
Table table = new Table() .....
BeanItemContainer data = new BeanItemContainer();
data.addBean( staffCard1 );
data.addBean( staffCard2 );
.....
.....
.....
table.setContainerDatasource(data);
// this will filter to shown only persons, which surname starts with "iva" , like Ivanoff, Ivanov etc...
// "staffSurname" is a name of a field in your StaffCard class
data.addContainerFilter("staffSurname", "iva", true, true);
P.S. the code above is just a live type to web form, may not compile due to mispells/mistypes