The following example shows how you can resize a DataGrid control in Flex using the rowCount property. By setting the rowCount property, the DataGrid control is automatically resized so that only the specified number of rows are displayed.
In Flex 3 (post beta 2, you can grab nightly versions of the Flex 3 SDK from the Adobe Labs Flex 3 SDK page) the DataGrid control’s rowCount and lockedRowCount properties do not include the header whereas in earlier versions of Flex 3 and Flex 2 they did. For example, the old behavior was to display 3 rows and the data grid header if you set the row count to 4. The new behavior is to display 4 rows and the data grid header (for a total of 5 rows). Yay!
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/11/01/resizing-a-flex-datagrid-control-using-the-rowcount-property/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white">
<mx:Array id="arr">
<mx:Object col1="1" col2="A" col3="a" />
<mx:Object col1="2" col2="B" col3="b" />
<mx:Object col1="3" col2="C" col3="c" />
<mx:Object col1="4" col2="D" col3="d" />
<mx:Object col1="5" col2="E" col3="e" />
<mx:Object col1="6" col2="F" col3="f" />
</mx:Array>
<mx:ApplicationControlBar dock="true">
<mx:Form>
<mx:FormItem label="rowCount:">
<mx:HSlider id="slider"
minimum="0"
maximum="{arr.length+1}"
value="4"
liveDragging="true"
snapInterval="1"
tickInterval="1"
dataTipPrecision="0" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:DataGrid id="dataGrid"
dataProvider="{arr}"
rowCount="{slider.value}" />
</mx:Application>
View source is enabled in the following example.
For an example of resizing the List control using the rowCount property, see “Resizing a Flex List control using the rowCount property”.



The previous example was compiled using the Flex 3 SDK (Version 3.0 build 186046).
Do you have any idea why rowCount of zero shows 7 rows? I assume that is a bug. Thanks.
Got the exactly same error, but instead of zero rows I had five, and when I added another one, it became 11 0_0.
hello -
is there any way of resizing the stage, that is to say, the dimensions of the embed tag, dynamically?
Leonhard; berlin
There seems to be a bug with showHeaders=false.
When the rowCount is 5 and there are 5 items, it shows 6 rows when it should only show 5.
Tim,
I believe it is a known issue, http://bugs.adobe.com/jira/browse/SDK-14463
Peter
If you have a main datagrid on a page with a percent height to take the maximum vertical place available.
And you would like to paginate to avoid scrollbars,…
Is there a way to get the actual rowcount displayed ? goal is to set the page size of my pagination system dynamically, cause it can be dependent of the resolution and browser settings of the user.
thank you.