SmartGwt : ListGrid setSortField setSortDirection 无效

本文介绍了一个关于 SmartGWT 中 ListGrid 组件排序的问题及解决方案。原本使用 setSortField 和 setSortDirection 方法无法正确实现排序,通过改用 setInitialSort 方法并结合 SortSpecifier 类成功解决了此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原创 收藏

开发环境:
JDK 1.6
Gwt2.0.3
SmartGwt 2.1
MyEclipse7.5 + gwt plugin
IE7.0

原先初始化 ListGrid UI 时,设置某列排序的代码如下:

说明:grid 中三列分别是标题,内容,更新时间,按照更新时间降序排列。

view plaincopy to clipboardprint?

1. public class CopyOfSystemNoticeListGrid extends ListGrid{
2.
3. public CopyOfSystemNoticeListGrid() {
4. setDataSource(DataSource.get("systemNotice"));
5. setAutoWidth();
6. setWidth100();
7. setSelectionType(SelectionStyle.SINGLE);
8.
9. ListGridField title = new ListGridField("title" , "标题" , 150);
10.
11. ListGridField content = new ListGridField("content" , "内容" );
12.
13. ListGridField updateTime = new ListGridField("updateTime" , "更新时间");
14. setFields(title , content , updateTime);
15. setSortField("updateTime");
16. setSortDirection(SortDirection.DESCENDING);
17. setAutoFetchData(true);
18. }
19. }

public class CopyOfSystemNoticeListGrid extends ListGrid{ public CopyOfSystemNoticeListGrid() { setDataSource(DataSource.get("systemNotice")); setAutoWidth(); setWidth100(); setSelectionType(SelectionStyle.SINGLE); ListGridField title = new ListGridField("title" , "标题" , 150); ListGridField content = new ListGridField("content" , "内容" ); ListGridField updateTime = new ListGridField("updateTime" , "更新时间"); setFields(title , content , updateTime); setSortField("updateTime"); setSortDirection(SortDirection.DESCENDING); setAutoFetchData(true); } }

SmartGwt 1.6 用到现在,升级了几个版本,不是何时,发现 UI 组件 ListGrid 按照以上代码设置时,grid中各行记录不能正常排序。不知道是否在sg版本升级时,API 中相关方法变更了,还是功能缺失了。

现在利用 setInitialSort方法,设置排序的代码如下,能正常排序。

view plaincopy to clipboardprint?

1. public class SystemNoticeListGrid extends ListGrid{
2.
3. public SystemNoticeListGrid() {
4. setDataSource(DataSource.get("systemNotice"));
5. setAutoWidth();
6. setWidth100();
7. setSelectionType(SelectionStyle.SINGLE);
8.
9. ListGridField title = new ListGridField("title" , "标题" , 150);
10.
11. ListGridField content = new ListGridField("content" , "内容" );
12.
13. ListGridField updateTime = new ListGridField("updateTime" , "更新时间");
14.
15. setFields(title , content , updateTime);
16. setInitialSort(new SortSpecifier[]{
17. new SortSpecifier("updateTime" , SortDirection.DESCENDING)
18. });
19. setAutoFetchData(true);
20. }
21. }

public class SystemNoticeListGrid extends ListGrid{ public SystemNoticeListGrid() { setDataSource(DataSource.get("systemNotice")); setAutoWidth(); setWidth100(); setSelectionType(SelectionStyle.SINGLE); ListGridField title = new ListGridField("title" , "标题" , 150); ListGridField content = new ListGridField("content" , "内容" ); ListGridField updateTime = new ListGridField("updateTime" , "更新时间"); setFields(title , content , updateTime); setInitialSort(new SortSpecifier[]{ new SortSpecifier("updateTime" , SortDirection.DESCENDING) }); setAutoFetchData(true); } }

如果有多重排序的话,只要添加新的 SortSpecifier 即可。

view plaincopy to clipboardprint?

1. setInitialSort(new SortSpecifier[]{
2. new SortSpecifier("updateTime" , SortDirection.DESCENDING),
3. new SortSpecifier("title" , SortDirection.ASCENDING)
4. });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值