GWT: How to implement filtering on CellTable? [duplicate]
Possible Duplicate:
GWT Table that supports dynamic filtering
I've been searching SO and do开发者_StackOverflow社区cs, but no success.
Is there already implemented some sort of mechanism for filtering a GWT (2.3) CellTable? By filtering I mean "show only those data that pass this condition".
The Google Guava library R09 has the static Collection2.filter(..)
method. The library had also been extended to work in GWT apps. To filter an instance of Collection<MyType>
before feeding it to your CellTable you can write something similar to:
List<MyType> filteredList =
new ArrayList<MyType>(Collections2.filter(unfilteredList,
new Predicate<MyType>() {
@Override
public boolean apply(MyType listItem) {
return (filterCondition) ? true : false;
}
}));
now filteredList
can be fed to your CellTable:
myCellTable.setRowCount(filteredList.size(), true);
myCellTable.setRowData(0, filteredList);
To use the library both guava-r09.jar
and guava-r09-gwt.jar
need to be added to your GWT project's classpath.
I've implemented filtering through implementing an AsyncDataProvider that queries the server using a querystring obtained from the current application place. The AsyncDataProvider updates the table automatically - you tell the AsyncDataProvider to update the table via:
addDataDisplay(final HasData<T> display)
If you're not familiar with Activities and Places, take a look at: http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html
For example, a history token for me looks like this:
EntityPlace:Source/q:sourceType_eq=report.
The AsyncDataProvider the uses the Place obtained from the history token to query the server.
HTH.
精彩评论