使用checkbox flex对两列datagrid进行排序

时间:2015-01-21 09:43:12

标签: actionscript-3 sorting flex datagrid actionscript

我在Flex应用程序的DataGrid中有5-6列。

<s:DataGrid id="recordGrid" dataProvider="{dxList}">

网格:

Selected  Name   field2   field2   field3

在第一列中有C​​heckBox。

第二列包含名称。等等...

目前没有选中复选框。现在,用户随机选择多个复选框,然后单击标题(选中)。然后它将首先对复选框进行排序。(我完成了它。)

但是,我的问题是第二个字段也按字母顺序排列

所有选定的记录都按字母顺序排列。然后在取消选中后,Record将按字母顺序显示。

我按照选中的复选框排序记录:

<s:GridColumn dataField="selected" sortDescending="true"> 

感谢。

1 个答案:

答案 0 :(得分:-1)

确保使用dataProvider的sort api。

示例摘自:http://www.java2s.com/Code/Flex/Grid/SortingaDataGridonmultiplecolumns.htm

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    initialize="initDP();" width="550" height="400">
    <mx:Script>

        import mx.events.DataGridEvent;
        import mx.collections.*;
        private var myDPColl:ArrayCollection;

        [Bindable]
        private var sortA:Sort;
        private var sortByColumn1:SortField;
        private var sortByColumn2:SortField;
        private var sortByColumn3:SortField;
        private var myDP:Array = [{Column1:'A', Column2:'AA',Column3:11.99, Column4: true},
                                  {Column1:'B', Column2:'BB',Column3:10.99, Column4: false},
                                  {Column1:'C', Column2:'CC',Column3:12.99, Column4: true},
                                  {Column1:'D', Column2:'VV',Column3:11.99, Column4: false},
                                  {Column1:'E', Column2:'EE',Column3:11.99, Column4: true},
                                  {Column1:'F', Column2:'FF',Column3:14.99, Column4: true},
                                  {Column1:'G', Column2:'GG',Column3:5.99,  Column4: true}
        ];
        private function initDP():void {
            myDPColl = new ArrayCollection(myDP);
            sortA = new Sort();
            sortByColumn1 = new SortField("Column1", true, true);
            sortByColumn2 = new SortField("Column2", true);
            sortByColumn3 = new SortField("Column3", true);
            sortA.fields=[sortByColumn1, sortByColumn2];
            myDPColl.sort=sortA;
            myDPColl.refresh();
            myGrid.dataProvider = myDPColl;
            myGrid.rowCount = myDPColl.length +1;
        }
        private function headRelEvt(event:DataGridEvent):void {
            sortA.fields[2] = sortA.fields[1];
            sortA.fields[1] = sortA.fields[0];
            if (event.columnIndex==0) {
                sortA.fields[0] = sortByColumn1;
            } else if (event.columnIndex==1) {
                sortA.fields[0] = sortByColumn2;
            } else {
                sortA.fields[0] = sortByColumn3;}
                myDPColl.sort = sortA;
                myDPColl.refresh();
                event.preventDefault();
        }

    </mx:Script>
    <mx:DataGrid id="myGrid" width="100%" headerRelease="headRelEvt(event);">
        <mx:columns>
            <mx:DataGridColumn minWidth="120" dataField="Column1"/>
            <mx:DataGridColumn minWidth="200" dataField="Column2"/>
            <mx:DataGridColumn width="75" dataField="Column3"/>
        </mx:columns>
    </mx:DataGrid>

</mx:Application>
相关问题