2 Replies Latest reply on Mar 20, 2008 3:29 AM by SatanClaus

    AdvancedDatagrid headerRenderer advanced question :-)

    czflex Level 1
      Hello, it;s really hard to explain my problem, but I will try anyway

      I have just one AdvancedDataGrid (imagine only one column) with a custom headerRenderer, which is just a Label, nothing more. The headerRenderer is actually a ClassFactory object which craeates that Label by calling newInstance() method, whenever Flex needs to create that Label object for the header, this is all clear.

      And my question is: when Flex calls the newInstance() and what Flex would do with the old Label object, when he creates a new instance?

      I am asking, because when I create this simple application, nothing special, Flex creates 2 Label objects for the header renderer. I know it because I put the 'trace' function into that Label. So whenever Datagrid redraws, I can see that there are two Label objects, both the same (the same header text), but only one is visible. I think, that the first Label is obsolete, because the second Label was created by newInstance() method, but the first one is still there, was not deleted nor removed from container (it was just moved into a AdvancedDataGridListContentHolder).

      So, both Labels are active, when datagrid redraws, both Labels updates, but just one is visible. so my question is why Flex creates two labels??

      Thanks, just for reading :-)
        • 1. Re: AdvancedDatagrid headerRenderer advanced question :-)
          Sreenivas R Adobe Employee
          ADG/DG create one set of itemRenderers used for doing measurements on required height of itemRenderers. These itemRenderers are hidden.

          This is the extra call you are seeing.
          • 2. Re: AdvancedDatagrid headerRenderer advanced question :-)
            SatanClaus
            I have even problem. But i create CheckBoxes.
            Here is how i implement CheckBox in my Column


            <mx:DataGridColumn dataField="maxDamage" headerText="100% Damage" editable="false">
            <mx:itemRenderer>
            <myComp:CheckBoxRenderer/>
            </mx:itemRenderer>
            </mx:DataGridColumn>


            And this is my CheckBoxRenderer:


            import mx.controls.CheckBox;
            import mx.controls.DataGrid;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.core.IFactory;
            import mx.events.CollectionEvent;
            import mx.events.FlexEvent;

            public class CheckBoxRenderer implements IFactory
            {

            public function newInstance():*
            {
            var checkBox:CheckBox = new CheckBox();
            checkBox.addEventListener(Event.CHANGE, onChange);
            checkBox.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
            return checkBox;
            }

            private function onChange(event:Event):void
            {
            var checkBox:CheckBox = event.target as CheckBox;
            if (checkBox == null) return;

            var dataGrid:DataGrid = checkBox.owner as DataGrid;
            // Field by data objects that must be midified
            var dataField:String = (dataGrid.columns[checkBox.listData.columnIndex] as DataGridColumn).dataField;
            checkBox.data[dataField] = checkBox.selected;

            dataGrid.dataProvider.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
            }

            private function onCreationComplete(event:FlexEvent):void
            {
            var checkBox:CheckBox = event.target as CheckBox;
            if (checkBox == null) return;

            var grid:DataGrid = checkBox.owner as DataGrid;
            if (grid == null) return;

            var dataField:String = (grid.columns[checkBox.listData.columnIndex] as DataGridColumn).dataField;
            if (dataField == null) return;

            checkBox.selected = checkBox.data[dataField];

            checkBox.dispatchEvent(new Event(Event.CHANGE));
            }
            }
            }


            Can anybody tell me, how must write my CheckBoxRenderer to haven't unvisible itemRenderers?
            With unvisible itemRenderer i have problem with checkboxes and they render unright...