注意到我们正在使用的DataGrid中的一个小排序问题。
单击DataGrid列标题时,会发生默认的交替升序/降序排序。精细。但是,如果列中的所有行项都相同,并且单击了列标题,则仍会进行某些排序,但仅适用于第一次单击,而后续单击时不会发生这种情况。
示例可在此处运行: http://megaswf.com/serve/1103850 单击“有库存”标题以查看问题。
<?xml version="1.0"?>
<!-- dpcontrols/DataGridSort.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initDP();" width="550" height="400">
<mx:Script>
<![CDATA[
import mx.collections.*;
private var myDPColl:ArrayCollection;
// The data source that populates the collection.
private var myDP:Array = [
{Artist:'Pavement', Album:'Slanted and Enchanted',
Price:11.99, InStock: true},
{Artist:'Pavement', Album:'Crooked Rain, Crooked Rain',
Price:10.99, InStock: true},
{Artist:'Pavement', Album:'Wowee Zowee',
Price:12.99, InStock: true},
{Artist:'Asphalt', Album:'Brighten the Corners',
Price:11.99, InStock: true},
{Artist:'Asphalt', Album:'Terror Twilight',
Price:11.99, InStock: true},
{Artist:'Asphalt', Album:'Buildings Meet the Sky',
Price:14.99, InStock: true},
{Artist:'Other', Album:'Other', Price:5.99, InStock: true}
];
//Initialize the DataGrid control with sorted data.
private function initDP():void {
myDPColl = new ArrayCollection(myDP);
myGrid.dataProvider=myDPColl;
}
]]>
</mx:Script>
<mx:DataGrid id="myGrid" width="100%" height="213">
<mx:columns>
<mx:DataGridColumn minWidth="120" dataField="Artist" />
<mx:DataGridColumn minWidth="200" dataField="Album" />
<mx:DataGridColumn width="75" dataField="Price" />
<mx:DataGridColumn width="75" dataField="InStock"
headerText="In Stock"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>