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开发者_如何学Go 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
Use a collection class (ArrayCollection or XMLListCollection), then sort it. More docs:
http://livedocs.adobe.com/flex/3/html/about_dataproviders_4.html#441147
http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/
<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.
精彩评论