目前我已经为 datagrid 实现了一个自定义标题,其中包括一个用于过滤的文本框和一个标题标题。当我单击文本框时,列排序并且我无法过滤。如果我删除排序部分,过滤工作正常。请提出任何想法,以便可以完成过滤和排序。下面是我的示例代码。(不包括所有内容,只是我显示了代码的相关部分)
public class TextBoxHeader<T> extends Header<String> {
public TextBoxHeader(String title, String width) {
super(new TextInputCell());
this.title = title;
if (width != null) {
this.width = width;
}
}
@Override
public void render(Context context, SafeHtmlBuilder sb) {
if (value == null) {
value = "";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<input type=\"text\" tabindex=\"-1\" value=\"" + value + "\" id=\"" + TEXT_BOX_ID
+ "\" style=\" width:130px");
//stringBuilder.append(width);
stringBuilder.append(" \" /> </input> <BR>");
stringBuilder.append(title);
sb.append(SafeHtmlUtils.fromSafeConstant(stringBuilder.toString()));
}
@Override
public void onBrowserEvent(Context context, Element elem, NativeEvent event) {
}
}
this sort event handler is in another class.
protected class DataGridSortEvent implements ColumnSortEvent.Handler {
@Override
public void onColumnSort(ColumnSortEvent event) {
System.out.println("inside DataGridSortEvent-->"+event.isSortAscending());
//customGrid.getDataProvider().refresh();
Collections.sort(customGrid.getDataProvider().getList(), nameComparator);
//customGrid.getDataProvider().refresh();
/*sortHandler.setComparator(name, new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
System.out.println("inside comparator");
return o1.getName().compareTo(o2.getName());
}
});*/
}
}
Any ideas to handle both (Sort and filter)???