12 Replies Latest reply on Nov 8, 2011 8:49 AM by Zolotoj

    Label as custom Item renderer

    Zolotoj Level 3

      Here is my Label custom renderer:

      package

      {

          import spark.components.Grid;

          import spark.components.Label;

          import spark.components.gridClasses.GridColumn;

          import spark.components.gridClasses.IGridItemRenderer;

       

          public class LabelItemRenderer extends Label implements IGridItemRenderer

          {

              public function LabelItemRenderer()

              {

                  //TODO: implement function

                  super();

              }

       

              public function get grid():Grid

              {

                  //TODO: implement function

                  return null;

              }

       

              public function get rowIndex():int

              {

                  //TODO: implement function

                  return 0;

              }

       

              public function set rowIndex(value:int):void

              {

                  //TODO: implement function

              }

       

              public function get down():Boolean

              {

                  //TODO: implement function

                  return false;

              }

       

              public function set down(value:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function get dragging():Boolean

              {

                  //TODO: implement function

                  return false;

              }

       

              public function set dragging(value:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function get hovered():Boolean

              {

                  //TODO: implement function

                  return false;

              }

       

              public function set hovered(value:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function get label():String

              {

                  //TODO: implement function

                  return null;

              }

       

              public function set label(value:String):void

              {

                  //TODO: implement function

              }

       

              public function get selected():Boolean

              {

                  //TODO: implement function

                  return false;

              }

       

              public function set selected(value:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function get showsCaret():Boolean

              {

                  //TODO: implement function

                  return false;

              }

       

              public function set showsCaret(value:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function get column():GridColumn

              {

                  //TODO: implement function

                  return null;

              }

       

              public function set column(value:GridColumn):void

              {

                  //TODO: implement function

              }

       

              public function get columnIndex():int

              {

                  //TODO: implement function

                  return 0;

              }

       

              public function prepare(hasBeenRecycled:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function discard(willBeRecycled:Boolean):void

              {

                  //TODO: implement function

              }

       

              public function get data():Object

              {

                  //TODO: implement function

                  return null;

              }

       

              public function set data(value:Object):void

              {

                  //TODO: implement function

                  trace(value);

              }

          }

      }

      Column definition:

      <editabledatagrid:EditableDataGridColumn

                          dataField="FamhistRelationshipCode"

       

                          editable="true"

                          headerText="Relationship">

                          <editabledatagrid:itemRenderer>

                              <fx:Component>

                                  <s:GridItemRenderer>

                                      <labelItemRenderer:LabelItemRenderer text="{data.FamhistRelationshipCode}"/>

                                  </s:GridItemRenderer>   

                              </fx:Component>

                          </editabledatagrid:itemRenderer>

                      </editabledatagrid:EditableDataGridColumn>  

      Initially datgrid is empty. At some point a row is added to its dataProvider, Why trace in set data would not trace?

       

      Thanks

        • 1. Re: Label as custom Item renderer
          saisri2k2 Level 4

          remove the <s:GridItemRenderer it is acting as a wrapper for the actual  itemrenderer and it is not alowing the data to be set onto tthe actual renderer ie., the label.

           

          <labelItemRenderer:LabelItemRenderer text="{data.FamhistRelationshipCode}" data={data}/> add the change i've made here, hopefully it has to work.

           

          Are you able to see the text ?

          • 2. Re: Label as custom Item renderer
            Zolotoj Level 3

            Here is what I am gettiing.

            I have a binding warning on data="{data}".  Also if I use the renderer at all then data property will be = null during ending of a data editing session and SDK will crash. I tried to use the renderer without setting data still the same. Here is my item renderer:

            package

            {

                import flash.events.Event;

               

                import spark.components.Grid;

                import spark.components.Label;

                import spark.components.gridClasses.GridColumn;

                import spark.components.gridClasses.IGridItemRenderer;

               

                public class LabelItemRenderer extends Label implements IGridItemRenderer

                {

                    public function LabelItemRenderer()

                    {

                        //TODO: implement function

                        super();

                    }

                   

                    public function get grid():Grid

                    {

                        //TODO: implement function

                        return null;

                    }

                   

                    public function get rowIndex():int

                    {

                        //TODO: implement function

                        return 0;

                    }

                   

                    public function set rowIndex(value:int):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get down():Boolean

                    {

                        //TODO: implement function

                        return false;

                    }

                   

                    public function set down(value:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get dragging():Boolean

                    {

                        //TODO: implement function

                        return false;

                    }

                   

                    public function set dragging(value:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get hovered():Boolean

                    {

                        //TODO: implement function

                        return false;

                    }

                   

                    public function set hovered(value:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get label():String

                    {

                        //TODO: implement function

                        return null;

                    }

                   

                    public function set label(value:String):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get selected():Boolean

                    {

                        //TODO: implement function

                        return false;

                    }

                   

                    public function set selected(value:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get showsCaret():Boolean

                    {

                        //TODO: implement function

                        return false;

                    }

                   

                    public function set showsCaret(value:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get column():GridColumn

                    {

                        //TODO: implement function

                        return null;

                    }

                   

                    public function set column(value:GridColumn):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get columnIndex():int

                    {

                        //TODO: implement function

                        return 0;

                    }

                   

                    public function prepare(hasBeenRecycled:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function discard(willBeRecycled:Boolean):void

                    {

                        //TODO: implement function

                    }

                   

                    public function get data():Object

                    {

                        //TODO: implement function

                        return null;

                    }

                   

                    public function set data(value:Object):void

                    {

                        //TODO: implement function

                        trace(value);

                   

                    }

                   

                }

            }

            Am I missing something here?

             

            Thanks for the help.

            • 3. Re: Label as custom Item renderer
              Zolotoj Level 3

              I was able to take of data being null. But now, when I end the editing session my item renderer (or what ever that might be) shows [object Object].

              Any idea?

               

              Thanks

              • 4. Re: Label as custom Item renderer
                saisri2k2 Level 4

                on override set data() set the text = data.someLabelToDisplay.

                • 5. Re: Label as custom Item renderer
                  saisri2k2 Level 4

                  I've a suggestion for you, if any of the above stuff does not work, since you are using flex > 4.0, i'll go with the default <S:ItemRenderer instead of the label which you are trying to get to work as a itmrenderer. and then i'll add this label as a child to this renderer. I would remvoe the wrapping <s:DAtaGridRenderer also.

                  • 6. Re: Label as custom Item renderer
                    Zolotoj Level 3

                    Yes, I am trying to.

                    But data.someLabelToDisplay in the debugger is already [object Object]

                    • 7. Re: Label as custom Item renderer
                      Zolotoj Level 3

                      Hre is what I have:

                      <editabledatagrid:itemRenderer>

                                             <fx:Component>                                       

                                                      <labelItemRenderer:LabelItemRenderer text="{data.FamhistRelationshipCode}" data="{data}"/>   

                                              </fx:Component>

                                          </editabledatagrid:itemRenderer>

                       

                      Is that what you mean? Also what about this data binding (data="{data}") warning? Is it OK? May be that's why it's not working.

                       

                      Thanks for the help.

                      • 8. Re: Label as custom Item renderer
                        Zolotoj Level 3

                        And this simply not compiling:

                        <editabledatagrid:itemRenderer>

                                                <fx:Component>                                       

                                                        <s:Label text="{data.FamhistRelationshipCode}" data="{data}"/>   

                                                </fx:Component>

                                            </editabledatagrid:itemRenderer>

                         

                        Cannot resolve attribute 'data' for component type spark.components.Label.

                        • 9. Re: Label as custom Item renderer
                          saisri2k2 Level 4

                          <editabledatagrid:itemRenderer>

                                                 <fx:Component>                                      

                                                          <labelItemRenderer:LabelItemRenderer //removed code here/>  

                                                  </fx:Component>

                                              </editabledatagrid:itemRenderer>

                           

                           

                          in the renderer

                           

                                  public function set data(value:Object):void

                                  {

                                        super.data = value;

                                         this.text = data.FamHistRelationshipCode; // if this is [object object] then try to see if this is object or text

                                         trace(value);

                           

                                  }

                           

                          <editabledatagrid:itemRenderer>

                                                  <fx:Component>                                      

                                                          <s:Label text="{data.FamhistRelationshipCode}" data="{data}"/>  

                                                  </fx:Component>

                                              </editabledatagrid:itemRenderer>

                           

                          the above code is not required(which is striked off)

                           

                          Message was edited by: saisri2k2

                          • 10. Re: Label as custom Item renderer
                            Zolotoj Level 3

                            If you say that the following is not needed then how to override set data?

                            <editabledatagrid:itemRenderer>

                                                    <fx:Component>                                      

                                                            <s:Label text="{data.FamhistRelationshipCode}" data="{data}"/>  

                                                    </fx:Component>

                                                </editabledatagrid:itemRenderer>

                            • 11. Re: Label as custom Item renderer
                              saisri2k2 Level 4

                              <editabledatagrid:itemRenderer>

                                                     <fx:Component>                                     

                                                              <labelItemRenderer:LabelItemRenderer //removed code here/> 

                                                      </fx:Component>

                                                  </editabledatagrid:itemRenderer>

                               

                              this stays as is in the datagrid

                               

                              LabelItemRenderer.mxml below. and nothing else.

                               

                              <s:ItemRenderer xmlns:s="">

                               

                              <script>

                               

                              // all your setters/getters go hre and then

                               

                                public function set data(value:Object):void

                                      {

                                            super.data = value;

                                             trace(value);

                               

                                      }

                               

                              </script>

                               

                              <s:Label text={data.something}/?

                              </s:ItemRenderer>

                              • 12. Re: Label as custom Item renderer
                                Zolotoj Level 3

                                I dont even have to use an Item Renderer.

                                It looks like the problem was with returning data from the Item Editor.

                                 

                                Thank you very much for the help.