DataGrid中文字符排序代码的介绍
来源:爱站网时间:2022-04-25编辑:网友分享
今天带大家来看看关于DataGrid中文字符排序代码的介绍是怎样的?如果你对这方面需要着重了解的话,可以跟随爱站技术频道小编来一探究竟,希望不会让你失望。
废话不多说,看例子:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12">
<mx:Script>
<!--[CDATA[
import com.SortUtil;
import mx.events.DataGridEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var ar:ArrayCollection = new ArrayCollection(
[{fieldA:"aaa", fieldB:"中文zhongwen"},
{fieldA:"bbb", fieldB:"字符zifu"},
{fieldA:"ccc", fieldB:"测试ceshi"},
{fieldA:"ddd", fieldB:"排序paixu"},
{fieldA:"eee", fieldB:"功能gongneng"},
{fieldA:"fff", fieldB:"示例shili"},
{fieldA:"ggg", fieldB:123},
{fieldA:"hhh", fieldB:false},
{fieldA:"iii", fieldB:"aaa"},
{fieldA:"iii", fieldB:"ggg"},
{fieldA:"jjj", fieldB:"1a2b"}]
);
private function onHeadReleaseHandle(event:DataGridEvent):void
{
SortUtil.setDataField(event.dataField);
}
]]-->
</mx:Script>
<mx:DataGrid width="100%" height="300" dataProvider="{ar}" headerRelease="onHeadReleaseHandle(event)">
<mx:columns>
<mx:DataGridColumn headerText="fieldA" dataField="fieldA"/>
<mx:DataGridColumn headerText="fieldB" dataField="fieldB"
sortCompareFunction="{SortUtil.sortChineseObject}"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12">
<mx:Script>
<!--[CDATA[
import com.SortUtil;
import mx.events.DataGridEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var ar:ArrayCollection = new ArrayCollection(
[{fieldA:"aaa", fieldB:"中文zhongwen"},
{fieldA:"bbb", fieldB:"字符zifu"},
{fieldA:"ccc", fieldB:"测试ceshi"},
{fieldA:"ddd", fieldB:"排序paixu"},
{fieldA:"eee", fieldB:"功能gongneng"},
{fieldA:"fff", fieldB:"示例shili"},
{fieldA:"ggg", fieldB:123},
{fieldA:"hhh", fieldB:false},
{fieldA:"iii", fieldB:"aaa"},
{fieldA:"iii", fieldB:"ggg"},
{fieldA:"jjj", fieldB:"1a2b"}]
);
private function onHeadReleaseHandle(event:DataGridEvent):void
{
SortUtil.setDataField(event.dataField);
}
]]-->
</mx:Script>
<mx:DataGrid width="100%" height="300" dataProvider="{ar}" headerRelease="onHeadReleaseHandle(event)">
<mx:columns>
<mx:DataGridColumn headerText="fieldA" dataField="fieldA"/>
<mx:DataGridColumn headerText="fieldB" dataField="fieldB"
sortCompareFunction="{SortUtil.sortChineseObject}"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
工具类SortUtil:
以后只要监听要排序列的headerRelease事件设置dataField就OK了,连sortCompareFunction的方法都不用写了。
DataGrid中文字符排序代码的介绍分享到这里就结束了,如果你对这方面有需要补充的,可以第一时间来爱站技术频道网站给小编留言。