10 Replies Latest reply on Jun 18, 2009 3:43 PM by Zolotoj

    Bind for fontWeight

    Zolotoj Level 3

      I am trying to do something like this:

      mx:DataGridColumn
      
       headerText="Customer" dataField="
      
      ccompany" fontWeight="{custlist.dataProvider.fontbold}"/>
      

      where custlist.dataProvider.fontbold caries either normal or bold.

       

      I am getting an error:

      Unknown Property: 'fontbold'.

       

      Any way to make it work?

       

      Thanks

       

       

        • 1. Re: Bind for fontWeight
          rtalton Level 4

          It can't find "fontbold" in your dataprovider. Make sure you are accessing the value in the dataprovider properly. Post a sample of your dataprovider for further help.

          1 person found this helpful
          • 2. Re: Bind for fontWeight
            Zolotoj Level 3

            Yeah... I see my mistake. I have to go with a custom renderer.

             

            My dataProvider is an XML.

            • 3. Re: Bind for fontWeight
              Zolotoj Level 3

              I also tried this:

               

              fontWeight="
              {custlist.dataProvider[custlist.listData.rowIndex].fontbold}"
              

              No errors, but no bolds either.

              • 4. Re: Bind for fontWeight
                rtalton Level 4

                Here's an example to help you.

                The datagrid uses an in-line item render for one column, a text component, which gets its fontWeight style directly from the data provider.

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                <mx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                       
                        [Bindable]
                        private var aryDataProvider:ArrayCollection = new ArrayCollection([
                            {fontweight:'bold', fontstyle:'normal'},
                            {fontweight:'normal', fontstyle:'normal'}
                            ]);
                    ]]>
                </mx:Script>
                    <mx:DataGrid dataProvider="{aryDataProvider}" x="124" y="109">
                        <mx:columns>
                            <mx:DataGridColumn headerText="Weight" dataField="fontweight">
                                <mx:itemRenderer>
                                    <mx:Component>
                                        <mx:Text fontWeight="{data.fontweight}" />
                                    </mx:Component>
                                </mx:itemRenderer>
                            </mx:DataGridColumn>
                            <mx:DataGridColumn headerText="Style" dataField="fontstyle"/>
                        </mx:columns>
                    </mx:DataGrid>  
                </mx:Application>

                • 5. Re: Bind for fontWeight
                  Zolotoj Level 3

                  Tried that, did not get any bolds though.

                   

                  Getting this:

                  warning: unable to bind to property 'fontbold' on class 'XML' (class is not an IEventDispatcher)

                  • 6. Re: Bind for fontWeight
                    rtalton Level 4

                    My example does not use XML, it is an array. The example works as-is. You need to adapt it to your XML dataprovider.

                    • 7. Re: Bind for fontWeight
                      rtalton Level 4

                      Note: please notice the 'data' property...

                      • 8. Re: Bind for fontWeight
                        Zolotoj Level 3

                        Thanks for keeping me helping.

                         

                        I tried this:

                         

                        <mx:DataGridColumn
                        
                         headerText="Customer" dataField="
                        
                        fontbold">
                        
                        <mx:itemRenderer>
                        
                        <mx:Component>
                        
                        <mx:Text fontSize="11" fontWeight="
                        
                        {listData[listData.rowIndex].fontbold}"> 
                        
                        </mx:Text>
                        
                        </mx:Component>
                        
                        </mx:itemRenderer> 
                        
                        </mx:DataGridColumn>
                        


                        No error, no warnings, but no bolds either. On row in the DataGrid does say bold.

                        • 9. Re: Bind for fontWeight
                          rtalton Level 4

                          Instead of

                          {listData[listData.rowIndex].fontbold}

                           

                          try

                          {data.fontbold}

                           

                          Remember that the data property is what you are after. See my code example again...

                          • 10. Re: Bind for fontWeight
                            Zolotoj Level 3

                            O yeah that works, thank you !!!