Flex s:datagrid排序似乎不起作用

时间:2012-02-18 18:13:05

标签: flex sorting datagrid flash-builder

我正在使用Flashbuilder 4.6并且无法在我的s:DataGrid中对列进行排序,单击列无效。任何人都可以提出错误的建议吗?

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:DataGrid x="30" y="24" requestedRowCount="4" sortableColumns="true">
        <s:columns>
            <s:ArrayList>
                <s:GridColumn dataField="dataField1" headerText="Column 1"></s:GridColumn>
                <s:GridColumn dataField="dataField2" headerText="Column 2"></s:GridColumn>
                <s:GridColumn dataField="dataField3" headerText="Column 3"></s:GridColumn>
            </s:ArrayList>
        </s:columns>
        <s:typicalItem>
            <fx:Object dataField1="Sample Data" dataField2="Sample Data" dataField3="Sample Data"></fx:Object>
        </s:typicalItem>
        <s:ArrayList>
            <fx:Object dataField1="4" dataField2="c" dataField3="data1"></fx:Object>
            <fx:Object dataField1="2" dataField2="d" dataField3="data2"></fx:Object>
            <fx:Object dataField1="1" dataField2="a" dataField3="data3"></fx:Object>
            <fx:Object dataField1="3" dataField2="b" dataField3="data4"></fx:Object>
        </s:ArrayList>
    </s:DataGrid>

</s:Application>

1 个答案:

答案 0 :(得分:7)

这是因为dataProvider的类型应该更改为ArrayCollectionArrayList基本上是一个更轻的&#34;版本ArrayCollection剥离了排序和过滤功能,当您单击列标题进行排序时,DataGrid会在后台使用这些功能。