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

梦想与她 提交于 2019-11-29 10:42:40

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.

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}"/>

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

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

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.

Mahesh
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

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.

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

Nikhil

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!