GWT中的编程CellTable排序不起作用

GWT中的编程CellTable排序不起作用

本文介绍了GWT中的编程CellTable排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ListDataProvider示例作为指南。根据提供的比较器,列正在按预期排序。我试图从这个例子中以编程方式应用这一行中的排序:

I'm using the ListDataProvider example here as a guide. The columns are sorting fine as expectd based on the provided comparators. I'm trying to programatically apply a sort as alluded to on this line from the example:

// We know that the data is sorted alphabetically by default.
table.getColumnSortList().push(nameColumn);

这是否会使单元格列显示为使用胡萝卜排序指示符进行排序。但是,底层数据并未排序。有没有办法让表格实际上按照顺序应用排序。我想我可以将它与通过Collections.sort()实际排序数据结合使用,但我想避免这种情况并在一个位置完成。

What this does, is it makes the cell column appear to be sorted with the carrot sort indicator. However, the underlying data isn't sorted. Is there a way to get the table to actually apply the sort progarmatically. I suppose I could use this in conjunction with actually sorting the data via Collections.sort(), but I'd like to avoid that and do it in one place.

推荐答案

您可以使用小exta代码以编程方式对列进行排序。下面的代码片段可以实现这一点 -

You can apply sorting on a column programatically with little exta code. The following code snippet does that -

当您将数据设置到cellTable时,您必须像下面的代码那样初始化ListHandler -

When ever u set data to the cellTable you have to initialize the ListHandler as below code does -

cellTable.addColumnSortHandler( createColumnSortHandler() );

private ListHandler<T> createColumnSortHandler()
{
     final ListHandler<T> listHandler = new ListHandler<T>(listDataProvider.getList());
     listHandler.setComparator( sortColumn, comparator );
     return listHandler;
}

当你想触发SortEvent时,执行下面的代码片段 - p>

And when u want to fire the SortEvent execute the following code snippet -

ColumnSortInfo columnSortInfo = new ColumnSortInfo( sortColumn, sortDirection );
cellTable.getColumnSortList().push( columnSortInfo );
ColumnSortEvent.fire( cellTable, cellTable.getColumnSortList());

这篇关于GWT中的编程CellTable排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 23:14