Flex4.5 DataGrid自动显示行号

今天在用Flex4.5 DataGrid自动显示行号时,在网上搜索了半天,都是说的Felx4 中如何自动显示行号,自己查阅Flex4.5API将问题解决,先将解决方法发上来,和大家分享下

1.创建一个项呈显器RowNumberItemRender,代码如下

 

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
     xmlns:s="library://ns.adobe.com/flex/spark"
     xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
 
 <fx:Script>
  <![CDATA[
   override public function set rowIndex(value:int):void{
    
    lblData.text=(value+1).toString();
   }
  ]]>
 </fx:Script>
 <s:HGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
  <s:Label id="lblData"/>
 </s:HGroup>
</s:GridItemRenderer>

 

2.在DataGrid中调用即可自动显示行号

 

<s:DataGrid  id="productData" width="820" height="430"  rowHeight="65"   requestedRowCount="6"     styleName="index_main_datagrid"  itemRenderer="pages.commpent.GridItemRender" skinClass="skin.skin1920.IndexDataSkin">
       <s:columns>
        <s:ArrayList>
         <s:GridColumn headerText="序号" width="80"    itemRenderer="pages.commpent.RowNumberItemRender"></s:GridColumn>
         <s:GridColumn dataField="productNo" headerText="产品工号" width="140"></s:GridColumn>
         <s:GridColumn dataField="productName" headerText="产品名称"></s:GridColumn>
         <s:GridColumn dataField="standardModel" headerText="规格型号" width="140"></s:GridColumn>
         <s:GridColumn dataField="units" headerText="单位" width="80"></s:GridColumn>
        </s:ArrayList>
       </s:columns>
      </s:DataGrid>

 

你可能感兴趣的:(datagrid)