0 Replies Latest reply on Apr 13, 2012 3:15 AM by Attila Andrei Aknai

    Problem with DataGrid/AdvancedDataGrid using variableRowHeight

    Attila Andrei Aknai

      I need a column with more that an information for example(title and description of a movie in the same cel)

      and for that I created a custorm renderer to hold the information togeter. Following the code for the renderer..

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
                    verticalScrollPolicy="off" horizontalScrollPolicy="off"
                    paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0">
             <mx:HBox horizontalGap="0">
                   <mx:Label text="Title:"/>
                   <mx:Label text="{data.title}"/>
             </mx:HBox>
             <mx:HBox horizontalGap="0" paddingLeft="3" paddingRight="3">
                   <mx:Label id="descLbl" text="Description:"/>
                   <mx:Text text="{data.description}" width="{width-6-descLbl.width}"/>
             </mx:HBox>
      </mx:VBox>
      

       

      Because I don't need something special when the data is get or set I didn't override that functions.

      Since the Text control need explicit width to wordWrap the text I binded that value to the available space instead of use "100%".

      Of course not all the descriptions has the same length and the description could take 1, 2, 3 or more rows so I set the valiableRowHeight of the grid to "true".

      When load everything works, mistakes comes when you try to enlarge the column to make a description to take less row (example row #1 before sesizig the description need 3 rows of text and after the resizing the descriotion need only 2 rows) as soon as you resized the column you notice that the text of the description effectly refreshed and takes only 2 rows but the height of the row could countain the 3rd row of the description that no more exists.

      If you do another resize operation the row height refresh correctly (example click on the column separator)

      I also tried to do table.validateNow(); on the mouse up event of the table.

      Following the code of a simple application.

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
             
             <mx:Script>
                   <![CDATA[                  
                          import mx.collections.ArrayCollection;
                          import mx.controls.Alert;
                          import mx.core.UIComponent;
                          import mx.events.FlexEvent;
                          [Bindable]
                          public var dp:ArrayCollection = new ArrayCollection([
                                 {title:"Ghost Rider: Spirito di vendetta", description:"Johnny Blaze, funambolo del motociclista " +
                                                                                                                               "trasformato in spirito della vendetta dal " +
                                                                                                                               "demonio in virtù di un patto firmato con il " +
                                                                                                                               "sangue per la salvezza del padre, vive " +
                                                                                                                               "ritirato, rifiuta il proprio status e la " +
                                                                                                                               "propria missione. A richiamarlo in attività " +
                                                                                                                               "è la Chiesa, in Romania infatti il diavolo " +
                                                                                                                               "si è palesato di nuovo per sguinzagliare " +
                                                                                                                               "nuovi sgherri alla ricerca di un bambino " +
                                                                                                                               "a cui tiene in maniera preoccupante."},
                                 {title:"La furia dei titani", description:"Gli uomini non pregano più, se ne sono " +
                                                                                                                               "disamorati dei loro dei, e come conseguenza " +
                                                                                                                               "questi stanno a poco a poco perdendo i " +
                                                                                                                               "propri poteri, compresa quell'immortalità " +
                                                                                                                               "che li rende sempre giovani. Alcuni sono " +
                                                                                                                               "anche morti. Intimoriti da quel che sta " +
                                                                                                                               "accadendo alcuni superstiti pianificano " +
                                                                                                                               "di riportare in vita Chronos dal Tartaro, " +
                                                                                                                               "spodestare Zeus e spazzare via il mondo. " +
                                                                                                                               "Per evitare il disastro viene richiamato " +
                                                                                                                               "in battaglia Perseo, che dopo aver sconfitto " +
                                                                                                                               "il mitologico Kraken si è ritirato a vita " +
                                                                                                                               "da pescatore. Sarà però costretto a rimettere " +
                                                                                                                               "mano alla spada dopo essere venuto a sapere " +
                                                                                                                               "dal morente zio Poseidone che il padre degli " +
                                                                                                                               "dei (nonchè suo) è stato catturato."},
                                 {title:"Paranormal Xperience 3D", description:"Un gruppo di studenti di psichiatria accetta la " +
                                                                                                                  "proposta del professore più autoritario della " +
                                                                                                                  "facoltà: andranno in un villaggio minerario " +
                                                                                                                  "abbandonato dove sarà loro possibile verificare " +
                                                                                                                  "se i fenomeni paranormali esistono veramente. " +
                                                                                                                  "Per il viaggio utilizzano un pulmino che viene " +
                                                                                                                  "fornito loro da Diana, sorella della studentessa " +
                                                                                                                  "Angela, che si unisce al gruppo. Sarà proprio il " +
                                                                                                                  "passato infantile delle due sorelle ad entrare " +
                                                                                                                  "drammaticamente nell'indagine."}
                          ]);
                          
                          
                          
                          protected function table_mouseUpHandler(event:MouseEvent):void
                          {
                                 table.validateNow();
                          }
                          
                   ]]>
             </mx:Script>
             
             <mx:VBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
                           width="500" height="500"
                           horizontalGap="0">
                   <mx:DataGrid id="table"    width="500" height="500"
                                                      dataProvider="{dp}" variableRowHeight="true" mouseUp="table_mouseUpHandler(event)">
                          <mx:columns>
                                 <mx:DataGridColumn id="titleCol" dataField="title" headerText="Title" wordWrap="true"/>
                                 <mx:DataGridColumn id="titDescCol" itemRenderer="CustomRenderer" wordWrap="true"/>
                          </mx:columns>
                   </mx:DataGrid>
             </mx:VBox>
      </mx:Application>
      
      

      The descriptions are in italian but for a simple example the langage of the text  doesn't matter

      Hope can you help me guys otherwise I will be creazy very soon trying to solve this problem.