6 Replies Latest reply on Nov 29, 2010 7:55 AM by linrsvp

    MYSQL text field not displaying correctly in Datagrid

    linrsvp

      Hi,

      I have a datagrid that gets its data from a webservice. The result involves a text field from the mysql database which is something like this :

       

      Hi,

       

      Some text here. Some More Text.

       

      Thanks

       

       

      When this field is displayed in the DataGridColumn, only the first line i.e "Hi," gets displayed. I tried setting the wordwrap and variableRowHeight to true. but dsnt work. I even set the ItemEditor to mx.controls.Text and mx.controls.TextArea. Still nothing. Any idea how to get the entire text to show in the column.

       

      One more thing worth mentioning is that I have the itemRenderer for this datagrid column to mx.controls.Label, so that if the textcontent is larger than the cell content, the datagrid will truncate the text and display a tooltip. So I expected the tooltip to appear in this case, but it dsnt.

       

      I have confirmed that the response from the webservice contains the entire text paragraph.. so it only means that things go wrong during the time of display...

       

      Please help!

        • 1. Re: MYSQL text field not displaying correctly in Datagrid
          flex2008 Level 3

          please post the code snippet for the datagrid you are using and I may be able to tell what needs to be done..

          • 2. Re: MYSQL text field not displaying correctly in Datagrid
            linrsvp Level 1

            This is my code :

             

             

                    <mx:DataGrid id="recentTicketsDG"
                                 dataProvider="{wsObj.getTickets.lastResult}"
                                 wordWrap="true" variableRowHeight="true"
                                 creationComplete="datagrid1_creationCompleteHandler(event)" >
                        <mx:columns>
                            <mx:DataGridColumn dataField="tn" headerText="Ticket No" headerStyleName="headerDG"/>
                            <mx:DataGridColumn dataField="title" width="150" headerText="Ticket Title" headerStyleName="headerDG" itemRenderer="mx.controls.Label"/>
                            <mx:DataGridColumn dataField="a_body"  width="200" itemEditor="mx.controls.Text" headerText="Ticket Body" headerStyleName="headerDG" itemRenderer="mx.controls.Label" />
                            <mx:DataGridColumn dataField="ticket_create_time" width="300" headerText="Create Time" headerStyleName="headerDG" />
                        </mx:columns>
                    </mx:DataGrid>

             

            wsObj is my webservice object. The line that I have underlined and highlighted is where the problem occurs. the mysql field in the table is a_body.

             

            Any idea ?

            • 3. Re: MYSQL text field not displaying correctly in Datagrid
              flex2008 Level 3

              Since you have used Label as item renderer you will get a .. when text width > label width.But here you are not getting it because text width might not be greater than label width.The text in question here is a multiline text.Label will show only single line.And the longest line in your data is also less than the label width.Hence no .. . You can check this by giving a long line in your data and it will show a .. and tooltip(if you are using Label as itemrenderer).

               

              The default item renderer will show the multiline text.So no need to specify any itemRenderer.You might have to set variableRowHeight to true.There is no need to use itemEditor to achieve what you are looking for.One more thing,an item editor will work only if you set the editable property of datagrid and the column where itemeditor is used are set to true.

               

              Hope I answered your question

              • 4. Re: MYSQL text field not displaying correctly in Datagrid
                linrsvp Level 1

                Hey thanks! that worked ...:)

                 

                 

                Though I am just curious, is there any way I can delete new lines in a string on the flex side ? I mean when I receive something like :

                 

                Hi,

                SOme text.

                Thanks!

                 

                I want to strip the string of newlines so that I get "Hi,Some text.Thanks". How can I accomplish that ?

                 

                Also, I am using a webservice response to load my datagrid i.e webserviceObj.functionname.lastResult. Is there any way I can count the number of rows in the response so that I can set the rowCount for my datagrid accordingly ? What wld be the best way to do this ?

                • 5. Re: MYSQL text field not displaying correctly in Datagrid
                  flex2008 Level 3

                  Use the replace() method in String class to replace the newline characters.

                  http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#replace%28% 29

                   

                  set rowCount = Array(webserviceObj.functionname.lastResult).length,assuming lastResult is an Array.But this can break the layout of components if the response has large number of rows(Assume you have 100 rows in response .Then the datagrid will have 100 rows and that will look weird).So I would rather give a constant rowCount  or  a height for datagrid and let the scrollbars come in case there are more rows.

                  1 person found this helpful
                  • 6. Re: MYSQL text field not displaying correctly in Datagrid
                    linrsvp Level 1

                    okk...thanks mate .. really appreciate your help