`
三问飞絮
  • 浏览: 316714 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

DataGrid/ArrayCollection排序问题总结

阅读更多

1,Find criteria must contain at least one sort field value.

Error: Find criteria must contain at least one sort field value. 
at mx.collections::Sort/findItem()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\Sort.as:491] 
at mx.collections::ListCollectionView/getItemIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:513] 
at ListCollectionViewCursor/collectionEventHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:2154] 
at flash.events::EventDispatcher/dispatchEventFunction() 
at flash.events::EventDispatcher/dispatchEvent() 
at mx.collections::ListCollectionView/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:833] 
at mx.collections::ListCollectionView/internalRefresh()[C:\autobuild\3.2.0

   

    网上有不少人碰到,但似乎不是同个问题。

    问题重现:先在DataGrid点击某列,进行排序。然后再新增一行新的记录。记录属性值为空。

    问题解决:

    A,实际解决方法

         通过排查,发现新增加的记录的对象定义中,如果有一个以上的字段类型定义为(*)的,就会抛出此项错误。

         如 var name:*;//出错

         改为 var name:Object;//正常

    B,查看源码(Sort.as 491行)

     if (compareFunction == null)  //436Line
        {///中间省略N行
             if (fieldsForCompare.length == 0)
                {
                 message = resourceManager.getString( //491Line
                  "collections", "findRestriction");
                    throw new SortError(message);
                }
         }
        else//505Line
        {
            compareForFind = compareFunction;
        }

      这里从436到505行之间的所有判断,都源于compareFunction为空的处理,如果为该ArrayCollection.sort属性设置排序函数,即不会进入这个判断语句中。[只是判断,未实践]

 

 

 2,排序顺序不正常(空值排中间)

  为DataGridColumn设置默认的排序函数。此处为继承了该类。

public function sortCompareFunctionHandler(rowa:Object,rowb:Object):int{
	var a:String  = itemToLabel(rowa);
	var b:String  = itemToLabel(rowb);
	if(a == b) return 0; 
	if(a == null || a == "") return -1;
	if(b == null || b == "") return 1;
			
	return ObjectUtil.stringCompare(a,b);
}

 

 



 

  • 大小: 17.1 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics