Reputation: 11
I want to sort items in the datagrid alphabetically by name.The order should be:
1) The name should first check for upeercase of the name if it is not then it should look for lowercase for the same letter alphabetically.
For example : if i have array of items say{Apple,boy,ant,Bat) then after sorting the list shld be
Apple ant Bat boy
Upvotes: 0
Views: 773
Reputation: 11
<mx:DataGrid id="planGrid" width="100%" height="100%" sortableColumns="true" resizableColumns="true" dragMoveEnabled="false" dragEnabled="false" draggableColumns="false" dataProvider="{contrList.dataProvider}"click="{displayPropertiesForPlan(event);}">
<mx:columns>
<mx:DataGridColumn sortCompareFunction="compareTypes" headerText="{msg('planner.editplan.name')}" wordWrap="true" itemRenderer="net.velti.mgage.mkt.views.campaignplans.planlist.NameItemRenderer" />
<mx:DataGridColumn width="200" headerText="{msg('planner.plans.grid.head.Status')}" itemRenderer="net.velti.mgage.mkt.views.campaignplans.planlist.StatusItemRenderer"/>
<mx:DataGridColumn id="dateColumn" width="250" headerText="{msg('planner.plans.grid.head.created')}" labelFunction="dateFunc" />
<mx:DataGridColumn sortCompareFunction="sortBudget" id="budgetColumn" width="120" headerText="{msg('planner.plans.grid.head.BudgetWithSign')}" labelFunction="budgetFunc" />
</mx:columns>
</mx:DataGrid>
My sort compare function is:
private function compareTypes(typeOne:Object, typeTwo:Object):int
{
var nameA:String = typeOne.name;
var nameB:String = typeTwo.name;
return ObjectUtil.stringCompare(nameA,nameB);
}
This doesn't sort in alphabetical order.
Upvotes: 0
Reputation: 39408
Use a collection class (ArrayCollection or XMLListCollection), then sort it. More docs:
http://livedocs.adobe.com/flex/3/html/about_dataproviders_4.html#441147
Upvotes: 1