0 Replies Latest reply on Oct 29, 2012 11:39 AM by Zolotoj

    Custom Item renderer

    Zolotoj Level 3

      I am working on Spark datagrid. I need to have a checkbox in one on its columns.

      Here is a fragment of my custom renderer:

      [Bindable]

      public class checkBoxColumnGrid extends HGroup implements IGridItemRenderer

      {

         .....

       

        override protected function childrenCreated():void

                          {

           super.childrenCreated();

           _checkBox = new CheckBox();

           _checkBox.addEventListener("change", onClick);

           this.addElement(_checkBox);

                          }

       

         public function set data(value:Object):void

                          {

           _data = value;

           _checkBox.selected = data[column.dataField] == "true" ? true: false;

                          }

       

        private function onClick(e:Event):void

                          {

           data[column.dataField] = String(_checkBox.selected);

                          }

       

         override public function set enabled(value:Boolean):void

                          {

           if (_checkBox)

             _checkBox.enabled = value;

                          }

       

      }

       

      Everything is working fine except the following.

      I aslo want to disable a checkbox after it has been clicked on on making it selected.

      For that I have this code in datgrid inplementation:

       

      <s:GridColumn dataField="addProduct" headerText="Add Product" sortable="false">

                                                        <s:itemRenderer>

                                                                  <fx:Component>

                                                                            <local:checkBoxColumnGrid enabled="{!data.getItemAt(column.columnIndex)}">

                                                                            </local:checkBoxColumnGrid>

                                                                  </fx:Component>

                                                        </s:itemRenderer>

                                              </s:GridColumn>

       

      But when I am clicking on a checkbox I am expecting it to get into set enabled code, but it's not getting there.

      Any idea?

       

      Thanks