【问题标题】:ActionScript: Sorting datagrid and getting data from specific cells programmaticallyActionScript:以编程方式对数据网格进行排序并从特定单元格获取数据
【发布时间】:2012-10-10 13:50:23
【问题描述】:

我的代码中有一个如下所示的数据网格:

<s:DataGrid id="dg">
  <s:ArrayCollection id="ac">
    <s:DataItem ../>
    <s:DataItem ../>
  </s:ArrayCollection>
</s:DatGrid>

在以特定方式对数据进行排序后,我试图让一个单独的标签(默认情况下)显示来自特定单元格的数据。

例如:

DataGrid shows:

Date  Type
----  ----
8     yes      
12    no
6     this
7     that

Label: 6 (First date after sorting in ascending order)

有什么简单的方法可以在 ActionScript(或其他方式)中做到这一点?我应该尝试使用 ArrayCollection 组件还是 DataGrid?

谢谢,

【问题讨论】:

    标签: sorting actionscript datagrid arraycollection


    【解决方案1】:

    我会研究 ArrayCollection 的排序功能: Sorting ArrayCollection

    【讨论】:

      【解决方案2】:

      使用sorting ArrayCollection 参考解决了这个问题。使用了两种不同的排序和提取方法:

      排序:

      private function sortFunction(a:Object, b:Object, array:Array = null):int
      {
        ..my sorting code..
      }
      
      public function Grid_onLoad(event:Event):void
      {
        var sort:Sort = new Sort();
        sort.compareFunction = sortFunction;
        items.sort = sort;
        items.refresh();
      }
      

      提取:

      public function FirstDate():String
      {
        return items.getItemAt(0).Date;
      }
      

      那么它只是适当地调用函数的问题:

      <s:DataGrid id="items" initialize="Grid_onLoad(event)">
        <s:ArrayCollection id="ac">
          <s:DataItem ../>
          <s:DataItem ../>
        </s:ArrayCollection>
      </s:DatGrid>
      
      <s:Label text="{FirstDate()}"/>
      

      【讨论】:

        猜你喜欢
        • 2013-06-02
        • 2013-05-17
        • 2022-06-26
        • 1970-01-01
        • 2018-03-26
        • 1970-01-01
        • 2020-01-28
        • 1970-01-01
        • 2013-11-03
        相关资源
        最近更新 更多