1 Reply Latest reply on Feb 23, 2010 2:01 AM by quoc_thai

    Scrolling on AdvancedDataGrid

    quoc_thai Level 1

      Hi all,


           I use AdvancedDataGrid to show data to user. I also wrote ItemRenderer called My_Renderer and set it to some ADG columns.

                1. From main mxml component, I used a static arraycollection to store my data called Old_Array.

                2. Inside My_Renderer, at the set data function, I compare current value of columns that I set My_Renderer with old value in Old_Array by get row index number from ADG, such as:

      override public function set data(value:Object):void{

                     super.data = value;

                     if (value != null){

                          currentValue = Number(listData.label);     --> Get new value column.

                          colName = (lisData as AdvancedDataGridListData).dataField; --> Get name of column.

                          rowIndex = (lisData as AdvancedDataGridListData).rowIndex; --> Get row index.

                          oldValue = Number(Old_Array[rowIndex][colName]);     --> Get the old value from static Old_Array

                          if (oldValue != currentValue){

                               bgColor = 0x000000;

                               Old_Array[rowIndex][colName] = currentValue;     --> Set new value to static Old_Array again to compare late.


                               bgColor = 0xFFFFFF;



                3. I override the updateDisplayList function:





      protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{


        super.updateDisplayList(unscaledWidth, unscaledHeight);


      var g:Graphics = graphics;



      if (bgColor != 0x000000){


      g.drawRect(0, 0, unscaledWidth, unscaledHeight);








                4. Some things from main mxml component such as:


      <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  xmlns:myadg="*" layout="absolute" creationComplete="init()">


         private function grdTop_OnScroll(event:ScrollEvent):void
          this.scrollPosition = event.position;
          grMain.verticalScrollPosition = this.scrollPosition;


      private function setData(event:ResultEvent):void{
             var arrResult:Array = event.result as Array;
             arrData = new ArrayCollection(arrResult);
             if (!isFlag){
               isFlag = true;
               Old_Array = arrData;
             grMain.dataProvider = arrData;
             grMain.verticalScrollPosition = this.scrollPosition;


      <mx:Box height="89">
        <mx:AdvancedDataGrid id="grMain" scroll="grdTop_OnScroll(event)" verticalScrollPolicy="auto" sortExpertMode="true" height="45">
          <mx:AdvancedDataGridColumn id="Id" headerText="Ma ID" dataField="ID"/>
          <mx:AdvancedDataGridColumn id="Name" headerText="Ten" dataField="NAME"/>
          <mx:AdvancedDataGridColumn id="Value" headerText="Gia tri" dataField="VALUE"/>

      <mx:RemoteObject id="StockInfo"
                   fault="faultHandler(event)" >
           <mx:method name="getTestData" result="setData(event)"/>


      5. Comparing inside My_Renderer is ok ! I can change background color for cells. My goal at here was success. But when make scrolling on ADG (down or up), drawing background color at some cells were wrong. I bugged my project and know that inside My_Renderer, value of row index not correct at:

                rowIndex = (lisData as AdvancedDataGridListData).rowIndex; --> Get row index.

      and so, when set new value back to Old_Array wrong array index:

                Old_Array[rowIndex][colName] = currentValue;     --> Set new value to static Old_Array again to compare late.


      It's mean when I scrolling on ADG, My_Renderer for some columns not right. I search at google, and know maybe I must extends AdvancedDataGrid and override the scrollVertically function but how I can do this to solve my problem ?