Problema de ajuste flexible de palabras usando mx: texto en AdvancedDataGrid itemRenderer cuando hay texto largo sin espacios

I am using AdvancedDataGrid in Flex 3. I'm setting variableRowHeight="true" on the grid and wordWrap="true" on the columns. The columns use an itemRenderer containing an mx:Text component within an HBox, so that I can use HTML text.

Everything is great, and my text is wrapping, except for when I've got a long string with no spaces. In this case, it is not wrapping at all. Instead, a scrollbar appears that totally obscures the text, because it doesn't expand the height of the cell to provide room for it. Is there any way to force Flex to break long strings like this, or some way I can do a work-around to get similar behavior? I know that mx:TextArea can break HTML text even when there's no spaces, so I'm not sure why it can't be done here, too.

Así es como se ve mi código:

<mx:AdvancedDataGrid width="100%" variableRowHeight="true">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="A" wordWrap="true">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:HBox width="100%">
                        <mx:Text htmlText="{data.a}"/>
                    </mx:HBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:AdvancedDataGridColumn>
        <mx:AdvancedDataGridColumn headerText="B" wordWrap="true">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:HBox width="100%">
                        <mx:Text htmlText="{data.b}"/>
                    </mx:HBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:AdvancedDataGridColumn>
    </mx:columns>
</mx:AdvancedDataGrid>

I tried adding an mx:TextArea component that is invisible except for when the mx:Text width is more than the mx:HBox width, in which case I make it visible and hide the mx:Text (in an overridden mx:HBox updateDisplayList or measure method). This kind of works, but scrolling up and down in the grid causes it to get messed up, with incorrect row heights. Code below:

<mx:AdvancedDataGrid width="100%" variableRowHeight="true">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="A" wordWrap="true">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:HBox width="100%">
                        <mx:Script>
                            <![CDATA[
                            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                                super.updateDisplayList(unscaledWidth, unscaledHeight);

                                if (this.width > 0 && text.width > this.width) {
                                    text.visible = false;
                                    text.includeInLayout = false;
                                    textArea.visible = true;
                                    textArea.includeInLayout = true;
                                } else {
                                    text.visible = true;
                                    text.includeInLayout = true;
                                    textArea.visible = false;
                                    textArea.includeInLayout = false;
                                }
                            }
                            ]]>
                        </mx:Script>
                        <mx:Text id="text" htmlText="{data.a}"/>
                        <mx:TextArea
                            id="textArea"
                            htmlText="{data.a}"
                            visible="false"
                            includeInLayout="false"
                            width="100%"
                            editable="false"
                            paddingLeft="0"
                            borderStyle="none"/>
                    </mx:HBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:AdvancedDataGridColumn>
    </mx:columns>
</mx:AdvancedDataGrid>

¿Alguien tiene alguna idea?

preguntado el 09 de marzo de 12 a las 23:03

Is there a reason you can't just always use TextArea, it would seem that would be easier and probably not cause the issues seen by removing/re-adding the components to the renderer as the user scrolls around (or during updateDisplayList). -

I would like to have the height of each cell resize to fit its contents, instead of having a fixed height for the TextArea, which would make each row the same size. -

Okay I think I'm following you, so my suggestion would be to extend mx:Text and override the public function set text in there use a TextField or another text object to temporarily assign the incoming text value to then use the line metrics to determine if it's larger than the width of it's container, if so run an algorithm to add each character one by one to the text field until it reaches the width of the parent container and add in carriage returns. help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/… -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.