I have a celltable with the following attributes (feature, Total, Pass, Fail) and I have a bunch of rows. 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. 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. i.e. 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). I am able to sort individually by column, when clicking on the header, using the following code:
First I mark the columns as sortable:
Then I add a create a ColumnSortHandler for each column, and add to the table like this:
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