Grouping Collection seperating numeric 5 from String "5"
- by invertedSpear
BackGround: I have an advanced data grid. The data provider for this ADG is an ArrayCollection. There is a grouping collection on an ID field of this AC.
Example of a couple items within this AC the AC var name is "arcTemplates":
(mx.collections::ArrayCollection)#0
filterFunction = (null)
length = 69
list = (mx.collections::ArrayList)#1
length = 69
source = (Array)#2
[0] (Object)#3
abbreviation = "sore-throat"
insertDate = "11/16/2009"
name = "sore throat"
templateID = 234
templateType = "New Problem"
templateTypeID = 1
[32] (Object)#35
abbreviation = 123
insertDate = "03/08/2010"
name = 123
templateID = 297
templateType = "New Problem"
templateTypeID = 1
[55] (Object)#58
abbreviation = 1234
insertDate = "11/16/2009"
name = 1234
templateID = 227
templateType = "Exam"
templateTypeID = 5
[56] (Object)#59
abbreviation = "breast only"
insertDate = "03/15/2005"
name = "breast exam"
templateID = 195
templateType = "Exam"
templateTypeID = 5
Example of Flex code leading to the Grouping:
<mx:AdvancedDataGrid displayItemsExpanded="true" id="gridTemplates">
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{arcTemplates}">
<mx:Grouping >
<mx:GroupingField name="templateTypeID" compareFunction="gcSort">
GC sort function:
public function gcSort(a:Object, b:Object):int{
return ObjectUtil.stringCompare(String(a.templateTypeID + a.name).toLowerCase(),
String(b.templateTypeID + b.name).toLowerCase());
}
Problem: In my AC example there are a few items, items 0, 32 and 56 properly sort and group to their templateTypeID, but item 55 does something weird. It seems to sort/group on the numeric 5 instead of the string "5". Gets stranger. If I change the name property to contain text (so 1234x) it then correctly sorts/groups to the string "5"
Question: What is going on here and how do I fix it?