user365559
user365559

Reputation: 11

Is there a way that i could sort items in datagrid Alphabetically in flex

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

Answers (2)

user365559
user365559

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

Related Questions