Apache flex 将FlexDataGrid安装到数据

Apache flex 将FlexDataGrid安装到数据,apache-flex,flex3,itemrenderer,Apache Flex,Flex3,Itemrenderer,我的文本数据行可以在0到100之间变化,并且所有数据都需要在屏幕上一次可见。默认行为适用于网格,直到行*rowHeight>gridHeight 基本上,我需要一个钩子到项目高度,或行高度来计算它的基础上的高度网格。我已经将paddingTop和paddingBottom设置为零,但行与行之间仍然有大量空白 我的datagrid组件 <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="OnCrea

我的文本数据行可以在0到100之间变化,并且所有数据都需要在屏幕上一次可见。默认行为适用于网格,直到行*rowHeight>gridHeight

基本上,我需要一个钩子到项目高度,或行高度来计算它的基础上的高度网格。我已经将paddingTop和paddingBottom设置为零,但行与行之间仍然有大量空白

我的datagrid组件

<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="OnCreationComplete()"
paddingTop="0"
paddingBottom="0"
>

<mx:Script>
    <![CDATA[

    private function OnCreationComplete():void
    {
        //setRowHeight(10);
    }

    override protected function setRowHeight(v:Number):void
    {
        super.setRowHeight(v);
    }

    ]]>
</mx:Script>

</mx:DataGrid>


setRowHeight()有帮助,但是如果我将行高度设置为10左右,则单元格大于单元格的itemRender。您可能希望查看DataGrid.variableRowHeight属性,因为当该属性设置为false(默认值)时,所有行的高度都将与最大的itemRenderer相同。您还可以考虑为每个DataColumn编写自己的itemRenderer

但是,如果您真正想做的是根据数据提供程序中的项目数设置行高,则可以这样设置DataGrid.rowHeight属性(假设网格具有固定高度,例如100%):

(我在这里发言是因为如果你最后得到一个小数,你需要一个滚动条)


我想您已经注意到,这种方法的唯一问题是itemRenderer可能无法在太小的行中正确显示。我想您可以通过根据高度更改渲染器中的字体来解决此问题。

您可能希望查看DataGrid.variableRowHeight属性,因为当此属性设置为false(默认值)时,所有行的高度都将与最大的itemRenderer相同。您还可以考虑为每个DataColumn编写自己的itemRenderer

但是,如果您真正想做的是根据数据提供程序中的项目数设置行高,则可以这样设置DataGrid.rowHeight属性(假设网格具有固定高度,例如100%):

(我在这里发言是因为如果你最后得到一个小数,你需要一个滚动条)


我想您已经注意到,这种方法的唯一问题是itemRenderer可能无法在太小的行中正确显示。我想你可以通过根据渲染器的高度改变其字体来解决这个问题。

谢谢你,这对我帮助很大。这是我的最后一个网格组件。因为有几次呼叫,它并不是完全独立的,但是如果它能帮助其他人工作,那就太好了

<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
paddingTop="-3"
paddingBottom="-3"
resize="OnResize(event)"
>

<mx:Script>
    <![CDATA[
        import mx.containers.Panel;
    import mx.core.Application;
    import mx.events.ResizeEvent;

    protected function OnResize(event:ResizeEvent):void
    {
        this.invalidateDisplayList();
    }

/**
 *  @private
 *  Sizes and positions the column headers, columns, and items based on the
 *  size of the DataGrid.
 */
override protected function updateDisplayList(unscaledWidth:Number,
                                              unscaledHeight:Number):void
{
    if( this.collection.length > 0 ) // so don't divide by zero
    {
        var appHeight:Number = Application.application.height;
        var appMinusMenuHeight:Number = appHeight - Application.application.hboxPrintBar.height;
        var boxHeight:Number = Application.application.vboxViewAll.height;
        if( boxHeight > 0 )
        {
            var gridHeight:Number = (appMinusMenuHeight - this.headerHeight) * 0.93;
            var calcHeight:Number = gridHeight / this.collection.length;
            var calcHeightFloor:Number = Math.floor( calcHeight );
            setRowHeight( calcHeightFloor );
            //var p:Panel = this.parent as Panel;
            //p.title = calcHeightFloor.toString();
            if( calcHeightFloor <= 10 )
                this.setStyle("fontSize",calcHeightFloor);
        }
    }
    super.updateDisplayList(unscaledWidth,unscaledHeight);
}

    ]]>
</mx:Script>

</mx:DataGrid>

0)//所以不要被零除
{
var appHeight:Number=Application.Application.height;
var-appMinusMenuHeight:Number=appHeight-Application.Application.hboxPrintBar.height;
var-boxHeight:Number=Application.Application.vboxViewAll.height;
如果(箱高>0)
{
var gridHeight:Number=(appMinusMenuHeight-this.headerHeight)*0.93;
var calcHeight:Number=gridHeight/this.collection.length;
var calcHeightFloor:Number=数学楼层(calcHeightFloor);
设置行高(calcHeightFloor);
//var p:Panel=this.parent作为Panel;
//p、 title=calcHeightFloor.toString();
如果(calcHeightFloor

谢谢你,这对我帮助很大。这是我的最后一个网格组件。由于一些调用,它不是真正独立的,但如果它能帮助其他人工作,那就太好了

<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
paddingTop="-3"
paddingBottom="-3"
resize="OnResize(event)"
>

<mx:Script>
    <![CDATA[
        import mx.containers.Panel;
    import mx.core.Application;
    import mx.events.ResizeEvent;

    protected function OnResize(event:ResizeEvent):void
    {
        this.invalidateDisplayList();
    }

/**
 *  @private
 *  Sizes and positions the column headers, columns, and items based on the
 *  size of the DataGrid.
 */
override protected function updateDisplayList(unscaledWidth:Number,
                                              unscaledHeight:Number):void
{
    if( this.collection.length > 0 ) // so don't divide by zero
    {
        var appHeight:Number = Application.application.height;
        var appMinusMenuHeight:Number = appHeight - Application.application.hboxPrintBar.height;
        var boxHeight:Number = Application.application.vboxViewAll.height;
        if( boxHeight > 0 )
        {
            var gridHeight:Number = (appMinusMenuHeight - this.headerHeight) * 0.93;
            var calcHeight:Number = gridHeight / this.collection.length;
            var calcHeightFloor:Number = Math.floor( calcHeight );
            setRowHeight( calcHeightFloor );
            //var p:Panel = this.parent as Panel;
            //p.title = calcHeightFloor.toString();
            if( calcHeightFloor <= 10 )
                this.setStyle("fontSize",calcHeightFloor);
        }
    }
    super.updateDisplayList(unscaledWidth,unscaledHeight);
}

    ]]>
</mx:Script>

</mx:DataGrid>

0)//所以不要被零除
{
var appHeight:Number=Application.Application.height;
var-appMinusMenuHeight:Number=appHeight-Application.Application.hboxPrintBar.height;
var-boxHeight:Number=Application.Application.vboxViewAll.height;
如果(箱高>0)
{
var gridHeight:Number=(appMinusMenuHeight-this.headerHeight)*0.93;
var calcHeight:Number=gridHeight/this.collection.length;
var calcHeightFloor:Number=数学楼层(calcHeightFloor);
设置行高(calcHeightFloor);
//var p:Panel=this.parent作为Panel;
//p、 title=calcHeightFloor.toString();
如果(calcHeightFloor