如何根据行数生成datagrid的序列号?

时间:2011-05-04 06:28:17

标签: flex flex-datagrid

如何根据行数生成数据网格的序列号?

1 个答案:

答案 0 :(得分:0)

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
         [Bindable]
          public var arrColl:ArrayCollection = new ArrayCollection([{col1:'',col2:'10',col3:'20'},{col1:'',col2:'10',col3:'20'},{col1:'',col2:'10',col3:'20'}])
           public function generateSerialId():void
           {

          var c:int= 0;
          for each(var obj:Object in arrColl)
         {
           obj.col1 = c;
           arrColl.removeItemAt(c);
           arrColl.addItemAt(obj,c);
           c++;

         }
         arrColl.refresh();
        }       
    ]]>
</mx:Script>
<mx:DataGrid x="2" y="63" dataProvider="{arrColl}">
    <mx:columns>
        <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
        <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
        <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
    </mx:columns>
</mx:DataGrid>
<mx:Button x="100" y="235" label="SerialID" click="generateSerialId()"/>
</mx:Application>