加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

排序 – 在应用程序的creationComplete(Flex 4.5)上设置Spark Da

发布时间:2020-12-15 02:16:41 所属栏目:百科 来源:网络整理
导读:我有一个带有几列的spark DataGrid组件,我希望我的应用程序默认在DataGrid的第一列上降序.我想使用单击顶部标题一次时发生的内置默认排序.我没有必要对我正在使用的ArrayCollection进行排序或更改比较器的内容. 我还想要任何用户生成的排序,例如单击不同列的
我有一个带有几列的spark DataGrid组件,我希望我的应用程序默认在DataGrid的第一列上降序.我想使用单击顶部标题一次时发生的内置默认排序.我没有必要对我正在使用的ArrayCollection进行排序或更改比较器的内容.

我还想要任何用户生成的排序,例如单击不同列的标题来覆盖默认排序.

有没有人对如何解决这个问题有任何想法?谢谢.

解决方法

只需使用sortByColumn方法:
var columnIndexes:Vector.<int> = Vector.<int>([ 0 ]);
dataGrid.sortByColumns(columnIndexes,true);

这是一个完整的例子:

DataGridSort.mxml

<?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"
    creationComplete="sortDataGrid();">

    <fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.collections.ArrayList;

        [Bindable]
        private var dataProvider:ArrayCollection = new ArrayCollection(
        [
            new Product("iPad","Detroit",599),new Product("iPod","Burbank",49),new Product("iPod Nano",39),new Product("Flash Drive",59),new Product("Galaxy Tab","Coldbridge",499),new Product("HTC Hero","Abidjan",700)
        ]);

        private function sortDataGrid():void
        {
            // you can also use Vector.<int>([ 0,1 ]); to sort by first 2 columns
            var columnIndexes:Vector.<int> = Vector.<int>([ 0 ]);

            // set 2nd argument to true to show sorting triangle
            dataGrid.sortByColumns(columnIndexes,true);
        }

    ]]>
    </fx:Script>

    <s:DataGrid id="dataGrid" horizontalCenter="0" verticalCenter="0" width="200"
        dataProvider="{dataProvider}">
        <s:columns>
            <s:ArrayCollection>
                <s:GridColumn dataField="name"/>
                <s:GridColumn dataField="location"/>
                <s:GridColumn dataField="price"/>
            </s:ArrayCollection>
        </s:columns>
    </s:DataGrid>

</s:Application>

Product.as

package
{
import flash.events.EventDispatcher;

public class Product extends EventDispatcher
{

    public function Product(name:String = null,location:String = null,price:Number = 0)
    {
        super();

        this.name = name;
        this.location = location;
        this.price = price;
    }

    public var name:String;

    public var location:String;

    public var price:Number;

}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读