Gwt celltable 对列调用排序
我有一个 Gwt 单元表。单击标题可以对列进行正确排序。 但在页面加载时,默认情况下不会对列进行排序。 我想在页面加载时对最右边的列进行排序。
I have a Gwt celltable. Clicking on the headers sorts the columns properly.
But on page load the columns are not sorted by default.
I want to make the right most column to be sorted when the page loads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了澄清几个现有的答案...
cellTable
的排序列表(由getColumnSortList()
函数访问)仅确定表头的状态,但实际上并不对任何数据进行排序。正如 @z00bs 所建议的,如果可能的话,在外部对数据进行排序可能是明智的。如果您知道数据将被预排序,那么您应该使用
getColumnSortList().clear()
和getColumnSortList().push()
函数向您的用户传达数据的排序方式。但是,如果您希望 CellTable 对数据进行实际排序,则需要触发一个事件来强制 CellTable 在客户端对组成数据进行实际排序。为此,您可以使用状态
ColumnSortEvent.fire()
方法,如下所示:这将触发一个事件,该事件根据标头的当前状态处理数据排序。因此,您可以首先设置标头所需的初始排序状态,然后执行此行以使数据排序实际反映标头中表示的当前排序状态。
To clarify a couple of the existing answers... a
cellTable
's sort list (as accessed by thegetColumnSortList()
function) only determines how the state of the table's header, but does not actually sort any data.As @z00bs suggested, it may be wise to sort the data externally, if possible. If you know that the data is going to be pre-sorted, then you should use the
getColumnSortList().clear()
andgetColumnSortList().push()
functions to communicate to your users how the data is sorted.If, however, you want the CellTable to actually sort the data, you're going to need to trigger an event to force the CellTable to actually sort the constituent data client-side. To do this, you can use the state
ColumnSortEvent.fire()
method, as such:This will trigger an event which handles the sorting of the data based on the current state of the header. So you could set the desired initial sort state of the header first, and then execute this line to actually make the data ordering reflect the current sort state represented in the header.
您可以使用 getColumnSortList() 并推送要排序的列,如下所示:
表将按给定列按升序排序。
调用此方法两次,将触发检查以测试给定列是否已推送到列表,如果是,则会按降序排序,因此要获取按列按降序排序的表,请使用:
在场景后面,该列被推送到表中名为 ColumnSortList 的内部列表中,位置为 0。每次单击列标题时都会更新相同的列表。
确保在初始化列后调用此方法。
You can use the getColumnSortList() and push the column you want to sort by, as such:
The table will be sorted by the given column in ascending order.
Calling this method twice, will trigger a check to tests if the given column already pushed to the list, and if so it will gets sorted in descending order, so to get the table sorted by the column in descending order use:
Behind the scene, The column is pushed to an inner list in the table called ColumnSortList to position 0. The same list is updated on each column header click.
Make sure you call this method after you initialized the column.
我建议您检索要显示的已排序数据。如果是这种情况,您只需设置正确的排序图标(升序或降序):
如果在检索之前无法对数据进行排序,您可以像用户单击标题时一样对列表进行排序(
onColumnSort(ColumnSortEvent event)
和Comparator
),然后再显示它。I'd suggest that you retrieve the data you're going to display already sorted. If that's the case you then only have to set the correct sort icon (ascending or descending):
If the data can't be sorted before retrieving you can sort the list the same way you do it when a user clicks the header (
onColumnSort(ColumnSortEvent event)
with aComparator
) before you display it.