views:

677

answers:

1

Hi Guys.

I have this datagrid which dataProvider is a ArrayCollection of 2 different types of objects (FolderVO and FileVO). I have a size column which in the case of the FolderVO is populated by an attribute called contentSize and in the case of the FileVO it is populated by the size attribute (the difference is handled by a itemrenderer).

This means that I need to implement a sorting function for the size column, here it is:

protected function sortSize(dataA:Object, dataB:Object):int{
  var order:int = 0;

  if(dataA is FolderVO && dataB is FolderVO){

   order = ObjectUtil.numericCompare(dataA.contentSize, dataB.contentSize);

  }else if(dataA is FileVO && dataB is FileVO){

   order = ObjectUtil.numericCompare(dataA.size, dataB.size);

  }else if(dataA is FolderVO && dataB is FileVO){

   order = 1;

  }else if(dataA is FileVO && dataB is FolderVO){

   order = -1;
  }

  return order;
 }

The Function runs pretty well, but after the return statement I get this error:

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\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1275]
at mx.collections::ListCollectionView/refresh()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:402]
at mx.controls::DataGrid/sortByColumn()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\DataGrid.as:3560]
at mx.controls::DataGrid/headerReleaseHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\DataGrid.as:4909]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9298]
at mx.controls.dataGridClasses::DataGridHeader/mouseUpHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\dataGridClasses\DataGridHeader.as:1259]

As you could notice, the error happens in the flex framework itself, not in my code. So I'm realy stucked here. Help will be greatly appreciated.

+1  A: 

Ok, I found it myself...

Apparently the error is caused because at some point the Flex Framework assumes that all the objects contained in the ArrayCollection have a size attribute so it attempts to get the value of it for something even when Im using a custom sorting function.

The solution was to add a dummy size attribute to my FolderVO with a default value of 0.

Hope this is helpful for someone out there.

Cheerz!

Chepech