对单元格表进行排序

对单元格表进行排序

本文介绍了GWT 对单元格表进行排序,可能只是我没有看到的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几个小时我一直在努力对 GWT CellTable 进行排序.这真的是一个愚蠢的问题,因为它已经在这里完成了http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable

I've been struggling for the last couple of hour trying to sort a GWT CellTable.It's really a stupid problem because it's been done herehttp://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable

但我不明白我在示例中遗漏了什么......

But I do not understand what I'm missing in the exemple ...

这是我用来创建列的代码:

Here is my code I use to create the column:

    Column<RemoteCommand, String> nbProducts = new Column<RemoteCommand, String>(
                new TextCell()) {
              @Override
              public String getValue(RemoteCommand object) {
                return object.getNumberProduct();
              }
            };
            nbProducts.setSortable(true);
            sortHandler.setComparator(nbProducts, new Comparator<RemoteCommand>() {
              public int compare(RemoteCommand o1, RemoteCommand o2) {
cellTable.redraw();
                  return o1.getCommandSize().compareTo(o2.getCommandSize());
                   // System.out.println(Integer.parseInt(o1.getCommandSize() ) -  Integer.parseInt(o2.getCommandSize()));
                    //  return  Integer.parseInt(o1.getCommandSize() ) -  Integer.parseInt(o2.getCommandSize());
              }
            });

这里是表格本身的声明:

And here is the declaration of the table itself:

// Add a selection model so we can select cells.
final SelectionModel<RemoteCommand> selectionModel = new MultiSelectionModel<RemoteCommand>(
            RemoteCommand.KEY_PROVIDER);
cellTable.setSelectionModel(selectionModel,
DefaultSelectionEventManager.<RemoteCommand> createCheckboxManager());


// Attach a column sort handler to the ListDataProvider to sort the list.
    ListHandler<RemoteCommand> sortHandler = new ListHandler<RemoteCommand>(values);
cellTable.addColumnSortHandler(sortHandler);

// Initialize the columns.
initTableColumns(selectionModel, sortHandler);

cellTable.setRowData(values);

需要帮助:)

推荐答案

我猜你已经找到了解决方案,但只是把它留在这里:

i guess You've already found the solution, but just to keep it here:

首先,使用一些已知列表创建您的 dataProvider.比具有相同 List 的 feed sortHandler;并使用列表更新数据.Celltable应该设置为dataProvider的dataDisplay:

First, create your dataProvider with some known List.Than feed sortHandler with same List;and use the list to update data.Celltable should be set as dataDisplay of the dataProvider:

List myDataList = new ArrayList();
ListDataProvider dataProvider = new ListDataProvider(KEY_PROVIDER);
dataProvider.setList(myDataList);
ListHandler sortHandler = new ListHandler(dataProvider.getList);
//tie provider and table
dataProvider.addDataDisplay(cellTable);

//when you need to update dataprovider
//first do some myDataList cleanup to remove old values
myListData.addAll(values);
//update data displays
dataProvider.refresh();

考虑一下,您必须始终使用同一个 List 对象.

Consider, you have to always use one and the same List object.

这篇关于GWT 对单元格表进行排序,可能只是我没有看到的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 08:35