[英]Sorting on different attributes in a GWT celltable Widget
I have a celltable with the following attributes (feature, Total, Pass, Fail) and I have a bunch of rows. 我有一个具有以下属性的celltable(功能,总计,通过,失败),我有一堆行。 I want to add support to sort by feature (which is a text) alphabetically or sort by fail (Integer).
我想添加支持按字母顺序按特征(按文本)排序或按失败排序(整数)。 Please note that I DON'T want to sort by feature and table both!
请注意,我不想按功能和表格排序! I want to sort by them individually.
我想单独按他们排序。 How do I achieve this?
我该如何实现这一目标?
One can add Column Sort Handlers using addColumnSortHandler method but this handler gets fired when I select any column that is sortable. 可以使用addColumnSortHandler方法添加列排序处理程序,但是当我选择任何可排序的列时会触发此处理程序。 If I add more than 1 column sort handler, all comparators get fired.
如果我添加多个列排序处理程序,则会触发所有比较器。 How do I make sure only the data gets sorted with the column I click.
如何确保仅使用我单击的列对数据进行排序。 ie if I click Feature heading, it should get sorted alphabetically.
即如果我单击功能标题,它应按字母顺序排序。 If I click Fail then it should sort by fail.. etc..
如果我单击失败然后它应该按失败排序..等等..
Any help would be appreciated. 任何帮助,将不胜感激。 Thank you
谢谢
Here's a code snippet 这是一段代码片段
final ListHandler<FeatureSummaryObject> failedColSortHandler = new ListHandler<FeatureSummaryObject>(dataProvider.getList());
failedColSortHandler.setComparator(failedCol, new Comparator<FeatureSummaryObject>() {
@Override
public int compare(FeatureSummaryObject o1, FeatureSummaryObject o2) {
return o1.getFailed() - o2.getFailed();
}
});
table.addColumnSortHandler(failedColSortHandler);
failedCol.setSortable(true);
ListHandler<FeatureSummaryObject> featureColSortHandler = new ListHandler<FeatureSummaryObject>(dataProvider.getList());
featureColSortHandler.setComparator(featureCol, new Comparator<FeatureSummaryObject>() {
@Override
public int compare(FeatureSummaryObject o1, FeatureSummaryObject o2) {
return o1.feature.compareTo(o2.feature);
}
});
table.addColumnSortHandler(featureColSortHandler);
featureCol.setSortable(true);
Regards, 问候,
I'm using a CellTable to display a list of files (File Name, Size, Mime Type). 我正在使用CellTable来显示文件列表(文件名,大小,Mime类型)。 I am able to sort individually by column, when clicking on the header, using the following code:
我可以使用以下代码在单击标题时按列进行单独排序:
First I mark the columns as sortable: 首先,我将列标记为可排序:
urlColumn.setSortable(true);
mimeColumn.setSortable(true);
sizeColumn.setSortable(true);
Then I add a create a ColumnSortHandler for each column, and add to the table like this: 然后我为每列添加一个创建ColumnSortHandler,并添加到表中,如下所示:
// Add sorting for the Name column
ListHandler<Asset> urlSortHandler = new ListHandler<Asset>(dataProvider.getList());
urlSortHandler.setComparator(urlColumn, new Comparator<Asset>() {
public int compare(Asset o1, Asset o2) {
....
}
});
table.addColumnSortHandler(urlSortHandler);
// Add sorting for the Size column
ListHandler<Asset> sizeSortHandler = new ListHandler<Asset>(dataProvider.getList());
sizeSortHandler.setComparator(sizeColumn, new Comparator<Asset>() {
public int compare(Asset o1, Asset o2) {
....
}
});
table.addColumnSortHandler(sizeSortHandler);
// Add sorting for the Type column
ListHandler<Asset> mimeSortHandler = new ListHandler<Asset>(dataProvider.getList());
mimeSortHandler.setComparator(mimeColumn, new Comparator<Asset>() {
public int compare(Asset o1, Asset o2) {
...
}
});
table.addColumnSortHandler(mimeSortHandler);
I added some logging and verified the appropriate sort handlers are being fired (meaning if I click file name, only the file name sort handler is invoked). 我添加了一些日志记录并验证了正在触发的相应排序处理程序(这意味着如果我单击文件名,则只调用文件名排序处理程序)。
Hopefully this sample code helps. 希望这个示例代码有所帮助。 If not, please provide some sample code which might help us to better diagnose the problem
如果没有,请提供一些示例代码,以帮助我们更好地诊断问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.