我正在使用gxt的LiveGrid。我想添加filters。我在下面添加了几行,但未过滤数据。我在这里错过任何东西吗?
GridFilters filters = new GridFilters();
filters.setLocal(true);
StringFilter nameFilter = new StringFilter("column name");
filters.addFilter(nameFilter);
filters.init(liveGrid);
liveGrid.addPlugin(filters);
答案 0 :(得分:2)
来自filter 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);
答案 1 :(得分:0)
GridFilters filters = new GridFilters(); filters.setLocal(真);
StringFilter nameFilter = new StringFilter(“column name”); filters.addFilter(nameFilter);
filters.init(liveGrid); liveGrid.addPlugin(过滤器);
如果你想在过滤器应用后得到数据你需要覆盖AbstractGridFilters的reload()方法。