LANE
LANE

Reputation: 139

How can I make datagrid height is equal to data content in Adobe Flex

In adobe Flex datagrid height is equally to fix height . I want to make datagrid height is depend data .

Upvotes: 6

Views: 22036

Answers (9)

Nikhil
Nikhil

Reputation: 1

Thanks Brat for your answer, that worked for me(in a way). There is just a little modification,when we calculate the height using above calculation a vertical scroll appears, we also need to set verticalScrollPolicy = "off" so that it never shows

Upvotes: 0

Yozef
Yozef

Reputation: 829

In Spark DataGrid you can set the requestedRowCount to the dataProviderLength, BUT on condition you Do Not Set a Height for the Datagrid.

Also, for a dataProvider that has a length of less than 3, It'll always show 3 rows.

Note Also Spark offers us requestedMaxRowCount & requestedMinRowCount.

Upvotes: 1

Mahesh
Mahesh

Reputation: 11

var rwcnt = xmllist.length();// dataprovider.length

ADG.rowHeight = 20;

var rht = ADG.rowHeight;

ADG.height = (rwcnt * rht) + 26;

this is what i got solution to control the size of advanced datagrid

Upvotes: 1

Fletch
Fletch

Reputation: 5219

Thanks for those saying:

<mx:DataGrid rowCount="{yourCollection.length}"/>

- this actually works for me in Flex 4. However I'd like to point out that according to the documentation "rowCount includes the header row", so I suppose the answer should be

<mx:DataGrid rowCount="{yourCollection.length + 1}"/>

Nevertheless, I think the doco is wrong because the former solution works for me.

Otherwise, does this help? http://www.actionscript.org/forums/showthread.php3?t=220962

Upvotes: 3

eBuildy
eBuildy

Reputation: 11

Of course, avoid in your datagrid MXML something like height="100%" or top="10" bottom="123"

Upvotes: 0

bart
bart

Reputation:

I get the same problem, using Flex SDK 3.3. I've seen several Adobe bug reports over the years regarding this, but the bug checkers always say it's resolved. Best thing I can suggest is to set an explicit pixel height on the datagrid, or you can try this:

dg.height = dg.measureHeightOfItems(0, dgDataProvider.length) + dg.headerHeight;

Bart

Upvotes: 4

gregilb
gregilb

Reputation:

Far and away the weirdest problem I've had with Flex is how to simply make Lists and DataGrids size to their contents (not show a scroll bar or any empty rows). I would've thought it would be totally straight forward even with variable row heights. It seems barely anyone else has this problem?!

<mx:DataGrid rowCount="{yourCollection.length}"/>

A repeatedly see the above solution - which doesn't work. I get a scroll bar and an extra blank row when there is more than one item in the collection.

Upvotes: 1

cliff.meyers
cliff.meyers

Reputation: 17734

I don't quite understand your question but if you are asking how to size the DataGrid to the number of rows in the dataProvider, you can try:

dataGrid.rowCount = yourCollection.length;

or

<mx:DataGrid rowCount="{yourCollection.length}"/>

Upvotes: 5

smartdirt
smartdirt

Reputation: 1037

You can set each row of the datagrid to fit based on the contents of a particular column of that row by setting the "variableRowHeight" attribute to true on the datagrid and setting the "wordWrap" attribute to true on the dataGridColumn that will contain the variable height content.

Upvotes: 6

Related Questions