Tuesday, September 7, 2010

DataGrid error - Find criteria must contain at least one sort field value

I got the above error message while doing some random tests on my current Flex application. This always seemed to be happening under the following scenario... a DataGrid was on the screen, the grid was binded to a collection (myVosArrayCollection). One of the gird columns data fields was pointing to a nested value (myVO.field.child) :

 <mx:DataGridColumn dataProvider="{myVosArrayCollection}" dataField="field.child".../>

It seems like Flex has a problem dealing with nested objects for dataGrid column dataField. My solution is adding a wrapper getter on myVO.field.child , for me this is only natural as I'm using a two level VOs hierarchy exactly for these sort of scenarios, the BaseVO and the VO it self (but that's something I'll cover on a different post). MyVo now have a new getter:

public class MyVO
private var field:Object;

public function get fieldChild():Object
return field.child;

my DataGrid now has the following setup:

 <mx:DataGridColumn dataProvider="{myVosArrayCollection}" dataField="fieldChild".../>
This solved the issue for me.


daniel cohen said...

see another solution http://natescodevault.com/?p=61

Lior Boord said...

Daniel, this is interesting, thanks. As I mentioned on the post above, I use a two levels VO concept which I'm hoping to discuss in a post some time soon, so for me the solution I showed is ideal.

Anonymous said...

Really great post .. It helped me alot. Thanks :)

Prerna Keshari said...

Thanks Lior Boord. it's a good trick :)