在AdvancedDataGridRendererProvider渲染时设置AdvancedDataGrid的行高

时间:2011-05-10 13:02:12

标签: flex itemrenderer advanceddatagrid

Flex Guys,

无法使用自定义AdvancedDataGridRendererProvider数据网格渲染器在AdvancedDataGrid中设置行的高度。

Snapcode就在这里

<mx:AdvancedDataGrid id="docId" 
                                     visible="true"
                                     width="100%" height="100%"
                                     dataProvider="{data}" 
                                     horizontalScrollPolicy="on"
                                     verticalScrollPolicy="on"
                                     styleName="MyStyle"
                                     styleFunction="getRowColours" 
                                     headerStyleName="MyStyle2"
                                     >
                    <mx:columns>
                        <mx:AdvancedDataGridColumn id="Name" dataField="name" 
                                                   headerText="Name" /> 
                        <mx:AdvancedDataGridColumn id="Value" dataField="values" 
                                                   headerText="Value" 
                                                   editable="true" />
                    </mx:columns>
                    <mx:rendererProviders>
                        <mx:AdvancedDataGridRendererProvider  id="DocID2"
                                                              columnIndex="1" columnSpan="1"
                                                              renderer="{new ClassFactory(MyRenderer)}" />
                    </mx:rendererProviders>
                </mx:AdvancedDataGrid>

请让我知道..我应该怎么处理它..

我尝试使用以下代码

为DataGrid设置variableRowHeight = true 然后,在你的rednrerer里面调整在运行时测量的高度 但我不应该以百分比来设置measuredHeight。

提前致谢。 的java

我重新编写了代码并使用代码ADG和渲染器代码

<mx:AdvancedDataGrid id="adg" dataProvider="{input}" height="350" variableRowHeight="true" >
        <mx:columns>
            <mx:AdvancedDataGridColumn dataField="company" headerText="Company"/>
            <mx:AdvancedDataGridColumn dataField="product" headerText="Product"/>
        </mx:columns>
        <mx:rendererProviders>
            <mx:AdvancedDataGridRendererProvider  id="myDataGridRenderer"
                                                  columnIndex="1" columnSpan="1"
                                                  renderer="{new ClassFactory(DataGridRowTestRenderer)}" />
        </mx:rendererProviders>
    </mx:AdvancedDataGrid>

    

    import spark.components.Label;
    import spark.components.TextArea;

    private var label1:Label;
    private var textArea1:TextArea;
    private var index:int;

    override public function set data(object:Object):void {
        super.data = object;

        this.removeAllElements();

        label1 = new Label();
        label1.text = object.company;

        this.addElement(label1);

        var textArea:TextArea = new TextArea();
        //textArea.text = object.product;
        //textArea.heightInLines = 2;

        index = object.index as int;

        textArea.heightInLines = index+1;

        textArea.text = object.product;
        /* if((index%2) == 0){
            textArea.heightInLines = 2;
        }else{
            textArea.heightInLines = 4;
        } */
        this.addElement(textArea);
    }

    override public function validateDisplayList():void{
        super.validateDisplayList();
    }

]]>

1 个答案:

答案 0 :(得分:3)

您尚未在ADG中设置variableRowHeight = true。如果你不想让它变量,你也可以使用rowHeight = Number。从那里,您的项目渲染器需要具有特定高度(数字)而不是百分比,否则它将无法工作。