废话不多说,看例子:
代码如下:
<?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)">