6 Replies Latest reply on Mar 21, 2011 10:50 AM by tooMuchTrouble

    best way to underline data in datagrid?

    tooMuchTrouble Level 3

      i need to underline text in a column based on certain criteria. i've tried a few approaches (itemRenderer using label.htmlText & setting styles) but the performance was pretty bad. can anyone suggest a better approach to this?

       

      thanks.

        • 1. Re: best way to underline data in datagrid?
          Codeflayer

          We would probably need some more information to fully help. Typically I just

          create a custom renderer and set the label styles based on parameters coming

          in from the data provider. You might be doing something odd that's causing

          the performance issue. Can you give us an example of the item renderer and

          the data provider?

          • 2. Re: best way to underline data in datagrid?
            tooMuchTrouble Level 3

            for the label.htmlText approach, pretty straight forward:

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"

                 xmlns:s="library://ns.adobe.com/flex/spark"

                 xmlns:mx="library://ns.adobe.com/flex/mx"

                  focusEnabled="true"

                 creationComplete="setText();">

            <fx:Script>

            <![CDATA[

            private function setText():void {

                 if (data.msgStatus=="_S")

                      lblData.htmlText="<u>S</u>";

                 else

                      lblData.htmlText=data.msgStatus;

            }

            ]]>

            </fx:Script>

             

            <mx:Label id="lblData" top="0" left="0" right="0" bottom="0" width="64"/>

            </s:MXDataGridItemRenderer>

             

            --oops forgot the style approach:

             

            <?xml version="1.0" encoding="utf-8"?>

            <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"

                 xmlns:s="library://ns.adobe.com/flex/spark"

                 xmlns:mx="library://ns.adobe.com/flex/mx"

                  focusEnabled="true"

                 creationComplete="setText();">

            <fx:Script>

            <![CDATA[

             

            private function setText():void {

                 if (data.msgStatus=="_S_")

                      lblData.styleName="deliveredMsg";

                 else

                 lblData.styleName="regularMsg";

            }

            ]]>

            </fx:Script>  

             

            <mx:Label id="lblData" top="0" left="0" right="0" bottom="0" width="64" text="{data.Message_Status}"/>

            </s:MXDataGridItemRenderer>

             

            this prerforms margianlly better but if you filter the datagrid or scroll much, the renderers are sticky & render that row of data, no matter the data.

             

            should i be using set data approach instead?

             

            thanks.

            • 3. Re: best way to underline data in datagrid?
              Codeflayer Level 1

              Ah, I see the problem. I've had really poor luck using creation complete

              methods within item renderers. It's due to the fact that the renderers get

              reused and not created again. That would probably be why you see strange

              behavior or performance problems. Try this instead:

               

              "value"</u>";

                    else

                         return value

                    }

              ]]>

              </fx:Script>

               

              <mx:Label id="lblData" htmlText="{setText(data)}" top="0" left="0"

              right="0" bottom="0" width="64"/>

              </s:MXDataGridItemRenderer

               

              • 4. Re: best way to underline data in datagrid?
                Codeflayer Level 1

                I hate it when my code gets munged in the email. Lets try this again:

                 

                <?xml version="1.0" encoding="utf-8"?>
                <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                        focusEnabled="true"
                       creationComplete="setText();">
                <fx:Script>
                <![CDATA[
                private function setText():void {
                       if (data.msgStatus=="_S")
                            lblData.htmlText="<u>S</u>";
                       else
                            lblData.htmlText=data.

                msgStatus;
                  }
                ]]>
                </fx:Script>
                 
                <mx:Label id="lblData" top="0" left="0" right="0" bottom="0" width="64"/>
                </s:MXDataGridItemRenderer>
                • 5. Re: best way to underline data in datagrid?
                  Codeflayer Level 1

                  HAHA! Third times the charm.

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx"
                          focusEnabled="true">
                  <fx:Script>
                  <![CDATA[
                  private function setText(value:Object):String {
                         if (value.msgStatus=="_S")
                              return "<u>"+value+"</u>";
                         else
                              return value
                        }
                  ]]>
                  </fx:Script>

                  <mx:Label id="lblData" htmlText="{setText(data)}" top="0" left="0" right="0" bottom="0" width="64"/>
                  </s:MXDataGridItemRenderer>
                  • 6. Re: best way to underline data in datagrid?
                    tooMuchTrouble Level 3

                    On 3/22/2011 12:12 AM, Codeflayer said:

                    >

                    HAHA! Third times the charm.

                     

                    thanks i'll give it a shot. yeah i see your point about creationComplete (and

                    now that you point it out, pretty obvious).