3 Replies Latest reply on May 18, 2007 5:24 AM by peterent

    Datagrid

    ppk_frnz
      Hi All,

      I'm facing a problem in datagrid. In a grid I'm displaying different data field values. I'm fetching values from a XML template. In the grid few columns will contains single values & few will contain multiple values (e.g. 2 different field values). Where 2 values will be displayed there value should be displayed such a manner where it will appear like we have splited the row into two section horizontally. Upto this part it is fine with me. I have used two text boxes as MX:Component & this has been placed within <MX:ItemRenderer>. Now, I have put a checking for the first data field, where text color will be in red if the value is less than 0. I'm unable to execute this part only. Can I have some help on this? I'm placing a code block below, which will show how I'm generating the columns.
      ------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------
      <mx:DataGridColumn id="PeriodCal96" dataField="CT_PeriodCal96" visible="false" sortCompareFunction="SetSortOrder" headerText="2006 &#13;- 1999" width="60" minWidth="60" textAlign="right">
      <mx:itemRenderer>
      <mx:Component>
      <mx:VBox horizontalAlign="right">
      <mx:HBox>
      <mx:Text text="{data.CT_PeriodCal96 == null ? '' :data.CT_PeriodCal96}&#13;{data.CT_RankABS_Cal_96m == null ? '' :data.CT_RankABS_Cal_96m}" textAlign="right"/>
      </mx:HBox>
      </mx:VBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      ------------------------------------------------------------------------------------------ -------------------------------------------------------------
      In the above code I need to put a check for "data.CT_PeriodCal96" value. This will be displayed in red text if the value is less than 0. I do have created a function which will check the value & change its color. But that works fine for single valued column where I can call the function in its "Itemrenderer" event. But for this case I'm unable to do so as I'm putting other components within the "ItemRenderer" event.

      It will be great help to me, if anyone help me out on this
        • 1. Re: Datagrid
          peterent Level 2
          Changing the color requires some ActionScript code. Before getting complex about it, try something like this:

          <mx:Text text="{ what you already have}" color="{data.CT_PeriodCal96 < 0 ? 0xff0000 : 0x000000}" />
          • 2. Re: Datagrid
            ppk_frnz Level 1
            Hi Peter,
            Thanks a lot. This works fine. But I just want to point out one thing when I tried the above code, I got error during compilation. It won't take < (less than sign). I got an error saying "The value of attribute "color" must not contain the '<' character." Instead of '<' sign if we use '>' or '==' sign this works fine. Not sure why this is happening?
            Earlier I had solved that issue (though that was bit complex process). There, I make a package. I defined one function there. This function reads the each column (reading by parent controls column index) field & their values. Then I put some validation there & apply the color logic. Finally the function returns the output as an HTML text. The above function was called in the datagrid ItemRenderer event.
            I found your tips very helpfull. Many thanks again. If possible then please let me know why I'm unable to apply '<' sign in the conditional part?
            • 3. Re: Datagrid
              peterent Level 2
              That's my fault; I always forget that you cannot easily have < (and even > sometimes) in XML. The XML parser thinks you are beginning a new XML element with the < character.

              You can use &lt; for the < and &gt; for > if need be.