SmartGwt : ListGrid setSortField setSortDirection 无效

原创   收藏

开发环境:
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. }); 

你可能感兴趣的:(jdk,UI,gwt)