GWT排序单元格表,可能只是我没有看到的东西 [英] GWT Sorting a cell table, probably just something i didn't saw

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

问题描述

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



但我不明白我缺少什么在例子中...

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

 列< 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());
}
});

这里是表格本身的声明:

  //添加一个选择模型,以便我们可以选择单元格。 
final SelectionModel< RemoteCommand> selectionModel = new MultiSelectionModel< RemoteCommand>(
RemoteCommand.KEY_PROVIDER);
cellTable.setSelectionModel(selectionModel,
DefaultSelectionEventManager。< RemoteCommand> createCheckboxManager());


//将列排序处理程序附加到ListDataProvider以对列表进行排序。
ListHandler< RemoteCommand> sortHandler = new ListHandler< RemoteCommand>(values);
cellTable.addColumnSortHandler(sortHandler);

//初始化列。
initTableColumns(selectionModel,sortHandler);

cellTable.setRowData(values);

help is requierd:)

解决方案

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



首先,用一些已知的List创建你的dataProvider 。
比使用相同的List提供sortHandler;
并使用列表更新数据。
Celltable应该设置为dataProvider的dataDisplay:

  List myDataList = new ArrayList(); 
ListDataProvider dataProvider = new ListDataProvider(KEY_PROVIDER);
dataProvider.setList(myDataList);
ListHandler sortHandler = new ListHandler(dataProvider.getList);
//绑定提供者和表
dataProvider.addDataDisplay(cellTable);

//当您需要更新数据提供者
时//首先执行一些myDataList清除以删除旧值
myListData.addAll(values);
//更新数据显示
dataProvider.refresh();

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


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 here http://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);

help is requierd :)

解决方案

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

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();

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆