3 Replies Latest reply on Mar 2, 2009 6:00 AM by Richard_Abbott

    sort alphanumeric values in  a data grid column

    ranjeeth_reddy
      Hi all,
      I have a datagrid column which contains AlphaNumeric values.Is there a way i can sort these values in a particular order(Eg: First Alphabetical and numerical).
      Thanx in advance
      Ranjeeth
        • 1. Re: sort alphanumeric values in  a data grid column
          Richard_Abbott Level 3
          Ranjeeth,
          check the help for DataGridColumn under the sortCompareFunction entry. You can write whatever you want as a sort function.
          Richard
          • 2. Re: sort alphanumeric values in  a data grid column
            ranjeeth_reddy Level 1
            Thanks for the response Richard,
            i have implemented the sortCompareFunction to sort integer values using the below code.

            private function sortNumeric(obj1:Object, obj2:Object):int {
            var value1:Number = (obj1.sequenceNumber == '' || obj1.sequenceNumber == null) ? null : new Number(obj1.sequenceNumber);
            var value2:Number = (obj2.sequenceNumber == '' || obj2.sequenceNumber == null) ? null : new Number(obj2.sequenceNumber);

            if (value1 < value2) {
            return -1;
            } else if (value1 > value2) {
            return 1;
            } else {
            return 0;
            }
            }

            But , i really dont have a clue on what needs to be done if the values are alphanumeric. could you suggest please
            Thanks ,
            Ranjeeth
            • 3. Re: sort alphanumeric values in  a data grid column
              Richard_Abbott Level 3
              Ranjeeth,
              the < and > operators work for strings as well as integers or floating point numbers, and generate a sort based on alphabetic order. So in English, capital letters are considered less than lower-case (I presume the sort is locale-sensitive for other character sets but have never done this). Have a look at the Flex help under Operators... less than and there are some specific examples there showing how different situations are handled.
              If for some reason alphabetic order is not appropriate then you'll have to write your own routine parsing the individual characters one at a time which I suspect would be a bit tedious! But you can do a few things to help yourself, like maybe if you don't want case-sensitive then just cast your entries all to lower case and test those. Or maybe is a special character has to be pulled out of the regular order then use a regular expression.
              Simplest case is when the alphabetic sort will do.
              Richard