1 Reply Latest reply on Jun 7, 2006 1:07 PM by ur_dtrain

    Cannot determine comparator for Sortfield

      I have a DataGrid that gets its data from an HttpService. If the first row of the data from the http request has a null value for a given field, I get the "Cannot determine comparator for Sortfield" error.

      I think the simplest workaround would be to specify the data type for each DataGridColumn. I see that the DataGridColumn objects can have a sortCompareFunction. I don't want to write my own custom comparators. I assume that the built-in comparators will do just fine.

      Suppose my MXML code looks something like this...

      <mx:DataGridColumn headerText="My String" dataField="name" sortCompareFunction="???"/>
      <mx:DataGridColumn headerText="My Integer" dataField="ss" sortCompareFunction="???"/>
      <mx:DataGridColumn headerText="My Float" dataField="gpa" sortCompareFunction="???"/>
      <mx:DataGridColumn headerText="My Date" dataField="birthdate" sortCompareFunction="???"/>

      What values would I use for the sortCompareFunctions in order to use the built-in comparators for the string, int, float and date types, respectively?
        • 1. Re: Cannot determine comparator for Sortfield
          ur_dtrain Level 1
          One trick that I've used in the past (which wont really give you type specific ability) is to check the returned data prior to assigning it as a dataProvider. In my case the data is xml based son I don't get nodes, but possible missing elements all together. I check for their existance for each row (in your case test for null) then assign a default value (-1 for int, 6/6/2006 for date etc...). After populating the 'voids' in my data I assign it as the dataProvider in ActionScript.

          To get more type specifc, you may want to look into using a data model and check out the validator classes.