首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex datagrid按数目字顺序,字母顺序排序

2012-10-25 
flex datagrid按数字顺序,字母顺序排序?xml version1.0 encodingutf-8?!-- http://blog.flexexam

flex datagrid按数字顺序,字母顺序排序

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/07/performing-case-insensitive-sorts-using-the-datagrid-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
??????? layout="vertical"
??????? verticalAlign="middle"
??????? backgroundColor="white">

??? <mx:Script>
??????? <![CDATA[
??????????? import mx.utils.ObjectUtil;

??????????? private function index_sortCompareFunc(itemA:Object, itemB:Object):int {
??????????????? // Make sure itemA has an "index" property.
??????????????? if (!itemA.hasOwnProperty("index")) {
??????????????????? itemA.index = null;
??????????????? }
??????????????? // Make sure itemB has an "index" property.
??????????????? if (!itemB.hasOwnProperty("index")) {
??????????????????? itemB.index = null;
??????????????? }
??????????????? // Perform a numeric sort.
??????????????? return ObjectUtil.numericCompare(itemA.index, itemB.index);
??????????? }

??????????? private function value_sortCompareFunc(itemA:Object, itemB:Object):int {
??????????????? // Make sure itemA has a "value" property.
??????????????? if (!itemA.hasOwnProperty("value")) {
??????????????????? itemA.value = null;
??????????????? }
??????????????? // Make sure itemB has a "value" property.
??????????????? if (!itemB.hasOwnProperty("value")) {
??????????????????? itemB.value = null;
??????????????? }
??????????????? /**
???????????????? * Perform a string sort. If the checkbox is selected
???????????????? * do a case insensitive sort, otherwise, dont.
???????????????? */
??????????????? return ObjectUtil.stringCompare(itemA.value, itemB.value, checkBox.selected);
??????????? }
??????? ]]>
??? </mx:Script>

??? <mx:ArrayCollection id="arrColl">
??????? <mx:source>
??????????? <mx:Array>
??????????????? <mx:Object index="1" value="apple" />
??????????????? <mx:Object index="200" value="Bear" />
??????????????? <mx:Object index="3" value="corn" />
??????????????? <mx:Object index="40" value="Dragon" />
??????????????? <mx:Object value="eggplant" />
??????????????? <mx:Object index="5" />
??????????? </mx:Array>
??????? </mx:source>
??? </mx:ArrayCollection>

??? <mx:ApplicationControlBar dock="true">
??????? <mx:CheckBox id="checkBox"
??????????????? label="case insensitive search:"
??????????????? labelPlacement="left"
??????????????? selected="true" />
??? </mx:ApplicationControlBar>

??? <mx:DataGrid id="dataGrid" dataProvider="{arrColl}">
??????? <mx:columns>
??????????? <mx:DataGridColumn dataField="index"
??????????????????? sortCompareFunction="index_sortCompareFunc" />
??????????? <mx:DataGridColumn dataField="value"
??????????????????? sortCompareFunction="value_sortCompareFunc" />
??????? </mx:columns>
??? </mx:DataGrid>

</mx:Application>

热点排行