0 Replies Latest reply on Dec 4, 2009 5:42 AM by CHAVALASD

    Urgent help required to make variableRowHeight & rowCount work hand in hand for a Datagrid

    CHAVALASD

      HI,

       

      I am using variableRowHeight property on a datagrid to wrap the text and this works perfectly.

       

      At the same time, I have to assign rowCount dynamically. My logic for caluculating rowCount is

      rowcount = sampleData.length > 5 ? 5:sampleData.length; where sampleData is my ArrayCollection. The caluculation happens correctly.

       

      The issue here is rows of the datagrid do not show correctly.

       

      From the post http://forums.adobe.com/message/2350643#2350643 I understood that both variableRowHeight & rowCount do not work hand in hand.

      So, I tried removing variableRowHeight and it works fine. The solution says using measureHeightOfItems and viewMetrics to calculate the height may solve the issue. I did not understand it very clearly.

       

      Can anyone let me know the solution with example.

       

      Thnaks

       

      Code

      =========

       

      <?xml version="1.0"?>

      <mx:Application

       

      xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"

      xmlns:itemren="

      com.itemren.*">

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.rpc.events.FaultEvent;

       

      import mx.rpc.events.ResultEvent;

       

      import com.vo.HeaderVO;

       

      import com.vo.DataVO;

       

      import mx.utils.ObjectUtil;

       

      import mx.collections.IViewCursor;

       

      import mx.controls.Alert;

       

      import mx.collections.ArrayCollection;

       

      [

      Bindable]

       

      public static var sampleData:ArrayCollection = new ArrayCollection ();

       

      [

      Bindable]

       

      public var rowcount:int;

       

       

      public function init():void {

       

      sampleData.addItem( { AssetNo :

      "234567890", AssetName : "Asset Name 1", Amount : "10000.02" } );

      sampleData.addItem( { AssetNo :

      "234567891", AssetName : "Asset Name 2", Amount :"2.04" } );

      sampleData.addItem( { AssetNo :

      "234567892", AssetName : "Asset Name 3", Amount : "4578.00" } );

      sampleData.addItem( { AssetNo :

      "234567893", AssetName : "Asset Name 4", Amount : "384.00" } );

      sampleData.addItem( { AssetNo :

      "234567894", AssetName : "Asset Name 5", Amount : "21454.20" } );

      sampleData.addItem( { AssetNo :

      "234567890", AssetName : "Asset Name 1", Amount : "10000.02" } );

      sampleData.addItem( { AssetNo :

      "234567891", AssetName : "Asset Name 2", Amount :"2.04" } );

      sampleData.addItem( { AssetNo :

      "234567892", AssetName : "Asset Name 3", Amount : "4578.00" } );

       

       

      trace ("sampleData.length ========= "+sampleData.length);

       

      rowcount = sampleData.length > 5 ? 5:sampleData.length;

       

      trace("count is ==== "+rowcount);

       

      dg.rowCount=rowcount;

       

      trace("dg.rowCount is === "+ObjectUtil.toString(dg.rowCount));

       

      dg.dataProvider=sampleData;

       

       

      }

       

      ]]>

       

      </mx:Script>

       

       

      <mx:Panel title="POC for dynamic rowCount of datagrid" height="100%" width="100%"

      paddingTop="

      10" paddingLeft="10" paddingRight="10">

       

       

      <mx:DataGrid id="dg" width="50%" wordWrap="true"

      variableRowHeight="

      true">

       

       

      <mx:columns>

       

      <mx:DataGridColumn dataField="AssetNo" headerText="Asset No" paddingLeft="20" />

       

      <mx:DataGridColumn dataField="AssetName" headerText="Asset Name" paddingLeft="20"/>

       

      <mx:DataGridColumn dataField="Amount" headerText="Amount" paddingLeft="20"/>

       

      </mx:columns>

       

      </mx:DataGrid>

       

      </mx:Panel>

       

      </mx:Application>