开发者

GWT how to do sorting CellTable with ListHandler and ListDataProvider

开发者 https://www.devze.com 2023-03-14 09:38 出处:网络
I have the following code taskDataProvider = new ListDataProvider<TaskHeader>(); taskDataProvider.addDataDisplay(taskTable);

I have the following code


taskDataProvider = new ListDataProvider<TaskHeader>();  
taskDataProvider.addDataDisplay(taskTable);
ListHandler<TaskHeader> columnSortHandler = new ListHandler<TaskHeader>(
            taskDataProvider.getList());
taskTable.addColumnS开发者_StackOverflow社区ortHandler(columnSortHandler);

//Some other code that modifies the list in taskDataProvider

When I click on the column header the ColumnSortEvent is fired but upon inspection I can see that the list in columnSortHandler is empty. Any modifications made to the taskDataProvider list have not been reflected in columnSortHandler. Am I missing something?


The example here seems to be exactly what you are looking for. From what you're showing of your code, I would say you are missing the comparator

columnSortHandler.setComparator(yourColumn,
        new Comparator<TaskHeader>() {
          public int compare(TaskHeader t1, TaskHeader t2) {
            return o1.field1.compareTo(o2.field1);
          }
        });

Also, when adding or removing data to your dataProvider, make sure you do not set a new list but add or remove data instead. Otherwise your dataProvider and listHandler will not be working with the same list ..

Don't :

taskDataProvider.setList(newList);

Do:

taskDataProvider.getList().add(newItem);
0

精彩评论

暂无评论...
验证码 换一张
取 消