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

flex_DataGridColumn汉语言按照首字母拼音排序

2012-11-06 
flex_DataGridColumn中文按照首字母拼音排序整个页面全粘出来了!费时费力啊,整了好长时间,不知道还有没有

flex_DataGridColumn中文按照首字母拼音排序
整个页面全粘出来了!
费时费力啊,整了好长时间,不知道还有没有别的好的方法。。。
<?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.collections.Sort;
            import mx.utils.ObjectUtil;
            import mx.utils.StringUtil;
   public  function isIn(min:int,max:int,n:int):Boolean{
      return min<=n && max>=n;
    }
   public  function convertChar(chineseChar:String):String
    {
   if(chineseChar!=null){
    var bytes:ByteArray = new ByteArray
     var str:String;
     for(var i:int=0;i<chineseChar.length;i++){
    bytes.writeMultiByte(chineseChar.charAt(i), "cn-gb");
    var n:int = bytes[i] << 8;
    n += bytes[i+1];
  
    if (isIn(0xB0A1, 0xB0C4, n))
     str=str+"a";
    if (isIn(0XB0C5, 0XB2C0, n))
     str=str+"b";
    if (isIn(0xB2C1, 0xB4ED, n))
     str=str+"c";
    if (isIn(0xB4EE, 0xB6E9, n))
    str=str+"d";
    if (isIn(0xB6EA, 0xB7A1, n))
     str=str+"e";
    if (isIn(0xB7A2, 0xB8c0, n))
    str=str+"f";
    if (isIn(0xB8C1, 0xB9FD, n))
     str=str+"g";
    if (isIn(0xB9FE, 0xBBF6, n))
     str=str+"h";
    if (isIn(0xBBF7, 0xBFA5, n))
     return "j";
    if (isIn(0xBFA6, 0xC0AB, n))
     str=str+"k";
    if (isIn(0xC0AC, 0xC2E7, n))
     str=str+"l";
    if (isIn(0xC2E8, 0xC4C2, n))
     str=str+"m";
    if (isIn(0xC4C3, 0xC5B5, n))
     str=str+"n";
    if (isIn(0xC5B6, 0xC5BD, n))
     str=str+"o";
    if (isIn(0xC5BE, 0xC6D9, n))
     str=str+"p";
    if (isIn(0xC6DA, 0xC8BA, n))
     str=str+"q";
    if (isIn(0xC8BB, 0xC8F5, n))
     str=str+"r";
    if (isIn(0xC8F6, 0xCBF0, n))
    str=str+"s";
    if (isIn(0xCBFA, 0xCDD9, n))
     str=str+"t";
    if (isIn(0xCDDA, 0xCEF3, n))
    str=str+"w";
    if (isIn(0xCEF4, 0xD188, n))
    str=str+"x";
    if (isIn(0xD1B9, 0xD4D0, n))
     str=str+"y";
    if (isIn(0xD4D1, 0xD7F9, n))
     str=str+"z";
   
     }
     return str;
    }
    return null;
    }
  
    private function value_sortCompareFunc(itemA:Object, itemB:Object):int {
      if (!itemA.hasOwnProperty("value")) {
                    itemA.value = null;
          }
               // Make sure itemB has a "value" property.
               if (!itemB.hasOwnProperty("value")) {
                   itemB.value = null;
              }
             
         var str1:String= convertChar(itemA.value);
           var str2:String=convertChar(itemB.value);
      return ObjectUtil.stringCompare(str1, str2, checkBox.selected);
             
   }
        ]]>
    </mx:Script>
    <mx:ArrayCollection id="arrColl">
        <mx:source>
            <mx:Array>
                <mx:Object index="1" value="阿董" />
                 <mx:Object  value="董珍宝" />
                 <mx:Object index="40" value="段远" />
                <mx:Object index="200" value="滨河村" />
                <mx:Object index="3" value="曹非" />
              
           
                <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"/>
            <mx:DataGridColumn dataField="value" sortCompareFunction="value_sortCompareFunc"/>
        </mx:columns>
    </mx:DataGrid>

</mx:Application>



热点排行