3 Replies Latest reply on Apr 22, 2011 6:16 AM by Sébastien VARLET

    Error: Find criteria must contain at least one sort field value.

    jmc42

      Hi

       

      I am getting the followng error in Sort.as when I click on a column in a DataGrid that is bound to a nested property (e.g. parent.name)

       

      Error: Find criteria must contain at least one sort field value.

       

      I can see why this is failing.

       

      In the findItem function of Sort.as the code tests whether there is data in line (456) hasFieldName = values[fieldName] !== undefined. This fails and so an error is raised later in the function by:

       

           if (fieldsForCompare.length == 0)

           {

           message = resourceManager.getString(

      "collections", "findRestriction");

       

                throw new SortError(message);

           }

       

       

      The code needs to traverse down the object hierarchy to get the field so that error is not thrown .

      The code needs to traverse down the object hierarchy to get the field so that error is not thrown .

       

      In the case of a non nested property, everything works fine.

       

      There is lots of discussion about nested properties in DataGrid and there is this jira:

       

      http://bugs.adobe.com/jira/browse/SDK-9801

       

      There is talk of using a labelFunction or an itemRenderer and other third party solutions (extensions of DataGridColumn).

       

      Is this a bug?  is there a workaround using labelFunction or itemRenderer which can stop the error in Sort.as?

       

      James

       

       

      Here is the code of findItem in Sort.as of SDK 3..4.0.9271

       

      public

       

       

       

       

       

      function findItem(items:Array,

      values:Object,

      mode:String,

      returnInsertionIndex:Boolean =

      false,

      compareFunction:Function =

      null):int

      {

       

      var compareForFind:Function;

       

      var fieldsForCompare:Array;

       

      var message:String;

       

       

      if (!items)

      {

      message = resourceManager.getString(

       

      "collections", "noItems");

       

      throw new SortError(message);

      }

       

      else if (items.length == 0)

      {

       

      return returnInsertionIndex ? 1 : -1;

      }

       

       

      if (compareFunction == null)

      {

      compareForFind =

      this.compareFunction;

       

      // configure the search criteria

       

       

      if (values && fieldList.length > 0)

      {

      fieldsForCompare = [];

       

      //build up the fields we can compare, if we skip a field in the

       

       

      //middle throw an error. it is ok to not have all the fields

       

       

      //though

       

       

      var fieldName:String;

       

      var hadPreviousFieldName:Boolean = true;

       

      for (var i:int = 0; i < fieldList.length; i++)

      {

      fieldName = fieldList[i];

       

      if (fieldName)

      {

       

      var hasFieldName:Boolean;

       

      try

      {

      hasFieldName = values[fieldName] !==

       

      undefined;

      }

       

      catch(e:Error)

      {

      hasFieldName =

      false;

      }

       

      if (hasFieldName)

      {

       

      if (!hadPreviousFieldName)

      {

      message = resourceManager.getString(

       

      "collections", "findCondition", [ fieldName ]);

       

      throw new SortError(message);

      }

       

      else

      {

      fieldsForCompare.push(fieldName);

      }

      }

       

       

      else

      {

      hadPreviousFieldName =

       

      false;

      }

      }

       

      else

      {

       

       

      //this is ok because sometimes a sortfield might

       

       

      //have a custom comparator

      fieldsForCompare.push(

       

      null);

      }

      }

       

      if (fieldsForCompare.length == 0)

      {

      message = resourceManager.getString(

       

      "collections", "findRestriction");

       

      throw new SortError(message);

      }

       

      else

      {

       

       

      try

      {

      initSortFields(items[0]);

      }

       

       

      catch(initSortError:SortError)

      {

       

      //oh well, use the default comparators...

      }

      }

      }

      }

       

       

      else

      {

      compareForFind = compareFunction;

      }