[英]GWT - CellTable sortable column won't respond to clicks
I have a GWT Celltable column that needs to be sorted alphabetically. 我有一个GWT Celltable列,需要按字母顺序排序。 I followed the official documentation and other questions posted here , but I have not been able to get it to work.
我按照官方文档和此处发布的其他问题进行了操作 ,但是我无法使用它。
I want the column to sort both ascending and descending. 我希望列对升序和降序进行排序。 Currently, the carat symbol shows up next to the column header but nothing happens when it is clicked.
目前,克拉符号显示在列标题旁边,但单击时没有任何反应。 There are no errors being thrown in the browser console either.
浏览器控制台中也没有抛出任何错误。
What am I doing wrong? 我究竟做错了什么? My obfuscated code -
我的混淆代码 -
public class MyClass extends Composite {
//other fields
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
@UiField CellTable<MyObject> myTable = new CellTable<MyObject>();
final ListDataProvider<MyObject> myDataProvider = new ListDataProvider<MyObject>();
@UiConstructor
public MyClass(...) {
initWidget(uiBinder.createAndBindUi(this));
// other initialization
buildMyTable();
}
buildMyTable() {
myDataProvider.addDataDisplay(myTable);
Column<MyObject, String> colA = new Column<MyObject, String>(new TextCell()) {
@Override
public String getValue(MyObject object) {
return object.getName();
}
};
Column<MyObject, String> colB = new Column<MyObject, String>(new TextCell()) {
@Override
public String getValue(MyObject object) {
return object.getAddress();
}
};
// created other columns
colA.setSortable(true);
myTable.addColumn(colA, "COL A");
myTable.addColumn(colB, "COL B");
// added other columns to the table
ListHandler<MyObject> columnSortHandler = new ListHandler<>(myDataProvider.getList());
columnSortHandler.setComparator(colA, new Comparator<MyObject>() {
@Override
public int compare(MyObject o1, MyObject o2) {
if (o1 == o2) {
return 0;
}
if (o1 != null) {
return (o2 != null) ? o1.getName.compareTo(o2.getName) : 1;
}
return -1;
}
});
myTable.addColumnSortHandler(columnSortHandler);
myTable.getColumnSortList().push(colA);
ColumnSortEvent.fire(myTable, myTable.getColumnSortList());
}
}
It is all about how do you add data to the CellTable
. 这是关于如何向
CellTable
添加数据的CellTable
。 For example, you can 例如,你可以
myDataProvider.setList(rowData);
or 要么
myTable.setRowData(rowData);
but both above methods will not allow the data to be sorted. 但上述两种方法都不允许对数据进行排序。 That is because, you already have
ListHandler
defined with an empty list. 那是因为,您已经使用空列表定义了
ListHandler
。 And it will not notice that the list have changed, so no sorting will be performed. 并且它不会注意到列表已更改,因此不会执行排序。
See ListDataProvider
documentation : 请参阅
ListDataProvider
文档 :
Modifications (inserts, removes, sets, etc.) to the list returned by getList() will be reflected in the model.
getList()返回的列表的修改(插入,删除,设置等)将反映在模型中。 However, mutations to the items contained within the list will NOT be reflected in the model.
但是,列表中包含的项目的突变不会反映在模型中。 You must call List.set(int, Object) to update the item within the list and push the change to the display, or call refresh() to push all rows to the displays.
您必须调用List.set(int,Object)来更新列表中的项目并将更改推送到显示,或调用refresh()将所有行推送到显示。 List.set(int, Object) performs better because it allows the data provider to push only those rows which have changed, and usually allows the display to re-render only a subset of the rows.
List.set(int,Object)执行得更好,因为它允许数据提供程序仅推送已更改的那些行,并且通常允许显示仅重新呈现行的子集。
So, you should first getList()
and change it like this: 所以,你应该先
getList()
并改变它:
myDataProvider.getList().clear();
myDataProvider.getList().addAll(rowData);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.