从过滤器javadoc :
要将过滤器添加到 Grid 列,请创建 Filter 的具体子类的实例,将列的 ValueProvider 传递给构造函数,然后将过滤器添加到 GridFilters
您的代码示例似乎过于严格,可能应该参数化。StringFilter 应该为您希望过滤的模型对象的属性提供一个 ValueProvider。以下是如何使用过滤器创建网格的简单概述。
假设您有一个类用户
public class User implements Serializable {
private String name;
private Integer id;
// Setters and getters
}
public interface UserProperties extends PropertyAccess<User> {
@Path("id")
ModelKeyProvider<User> key();
ValueProvider<User, String> name();
}
要创建一个将显示您的用户的网格,您将执行以下操作
private static final UserProperties props = GWT.create(UserProperties.class);
...
// Create column config
ColumnConfig<User, String> nameCol = new ColumnConfig<User, String>(props.name(), 200, "Name");
// Create column model
List<ColumnConfig<User, ?>> l = new ArrayList<ColumnConfig<User, ?>>();
l.add(nameCol);
ColumnModel<User> cm = new ColumnModel<User>(l);
// Create User store
ListStore<User> store = new ListStore<User>(props.key());
// Create your grid
final LiveGridView<User> liveGridView = new LiveGridView<User>();
liveGridView.setForceFit(true);
Grid<User> view = new Grid<User>(store, cm) {
@Override
protected void onAfterFirstAttach() {
super.onAfterFirstAttach();
// Get grid data
}
};
// Create a String filter for the column
StringFilter<User> nameFilter = new StringFilter<User>(props.name());
// Create a GridFilters
GridFilters<User> filters = new GridFilters<User>();
filters.initPlugin(grid);
filters.setLocal(true);
filters.addFilter(nameFilter);