5 Replies Latest reply on Jul 14, 2011 8:18 AM by vcbcpna3465

    Applying an item renderer when a newly added row is visible

    vcbcpna3465 Level 1

      Hi all,

       

      I have an issue where if I add a new row to an advanceddatagrid that is NOT visible on the grid (since the newly added row is at the end of the grid), the renderer never fires when the newly added row becomes visible ie.  user scrolls down to the end.

       

      Right now, all of my rendering "logic" is done in the set data method.  Is there another method I need to override in order for the renderer to be applied when the row becomes visible ie when the user user scrolls down to the end of the method?

       

      I am adding a new row via databinding. ie new Object().

       

      Thanks in advance.

        • 1. Re: Applying an item renderer when a newly added row is visible
          kokorito Level 4

          have you tried calling validateNow() on the datagrid after the row is added?

          • 2. Re: Applying an item renderer when a newly added row is visible
            saisri2k2 Level 4

            Probably the IList which is assigned as a data provider to he datagid is not bindable? Can you post some of your code here? like the dataprovider declaration and definition of the datagrid. and how you assign the data to the datagrid?

            • 3. Re: Applying an item renderer when a newly added row is visible
              vcbcpna3465 Level 1

              The data grid is bindable:  Definition here:

               

              <mx:AdvancedDataGrid useRollOver="false" itemClick="handleItemClick(event)" width="100%" height="100%"

              dataProvider="

              {mdl.gridData}" editable="true" id="dg">

               

              <mx:groupedColumns>

               

              ItemRenderer declaration here.  I add the renderer to select columns in the datagrid

               

              public function onComplete():void {

               

              //cost.headerRenderer = new ClassFactory(RiskCostEstimatesRenderer);

              strat.itemRenderer =

              new ClassFactory(ExecutionGridComboBoxRenderer);

              starttime.itemRenderer =

              new ClassFactory(ExecutionGridEditableItemRenderer);

              endtime.itemRenderer =

              new ClassFactory(ExecutionGridEditableItemRenderer);

               

              partrate.itemRenderer =

              new ClassFactory(ExecutionGridEditableItemRenderer);

              urgency.itemRenderer =

              new ClassFactory(ExecutionGridEditableItemRenderer);

               

              // action.itemRenderer = new ClassFactory(DeleteColumnItemRenderer);

              mdl.initPM();

              }

               

              add function: You'll see that i add the the new row by adding to the model which is bound to the data grid.

               

              var n:ProjectedExecutionStats = new ProjectedExecutionStats();

              mdl.gridData.addItem(n);

               

              On add item, the object gets appended to the end of the grid.  However, the row is NOT visible in the grid.  When I scroll down the itemrenderer set data gets fired.  However, it seems like the rowIndex in the listData is not equal to the rowIndex of the datagrid as I'd expect.  That may be the root of the problem.  See bold red.

               

              Here is the relevant code:

               

              Class definition here:

               

              private var _listData:BaseListData;

               

              private var _dataGrid:AdvancedDataGrid;

              [

              Bindable]

               

              public var indVis:Boolean= true;

              [

              Bindable]

               

              var indIncludeInLayout:Boolean=true;

               

               

              public function get listData():BaseListData

              {

               

              return _listData;

              }

               

               

              public function set listData(value:BaseListData):void

              {

               

              if (value == null) return;

              _listData = value;

              }

               

              private function changeToEditableState():void {

               

               

              var adg:AdvancedDataGrid = owner as AdvancedDataGrid;

               

              var gridListData:DataGridListData = DataGridListData(listData);

               

              var rowIndex:int = gridListData.rowIndex + adg.verticalScrollPosition;

               

              var colIndex:int = gridListData.columnIndex;

              // adg.collectionLength;

               

              // only change to editable state if the current row is the last row.

               

              if ( (adg.dataProvider.length-1) == rowIndex)

              adg.editedItemPosition = {columnIndex:colIndex, rowIndex:rowIndex};

              }

               

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

              {

               

              this.indVis = true;

               

              this.includeInLayout = true;

               

              if (value == null){

               

              this._dataGrid = null;

               

              this._listData = null;

               

              this.includeInLayout = true;

               

              this.indVis = true;

              adg.validateNow();

               

              return;

              }

               

              var gridListData:AdvancedDataGridListData = AdvancedDataGridListData(listData);

               

              var adg:AdvancedDataGrid = owner as AdvancedDataGrid;

              // adg.scrollToIndex(ArrayCollection(adg.dataProvider).length-1);

               

              super.data = value;

               

              var rowIndex:int = gridListData.rowIndex;

              // var rowIndex:int = gridListData.rowIndex + adg.verticalScrollPosition;

              // var colIndex:int = gridListData.columnIndex;

               

              var isNew:Boolean = value["isNew"];

               

              var itm:ProjectedExecutionStats = gridListData.item as ProjectedExecutionStats;

               

              var stratindropdown = itm.strategy;

               

              dlabel.text = gridListData.label;

               

               

               

               

              if (isNew &&

              ((stratindropdown==

              "VWAP" && (gridListData.dataField=="startTime" || gridListData.dataField=="endTime"))

              || (stratindropdown==

              "TARGET_STRIKE" && (gridListData.dataField=="startTime" || gridListData.dataField=="endTime" || gridListData.dataField=="urgency"))

              || (stratindropdown==

              "WITH_VOLUME" && (gridListData.dataField=="startTime" || gridListData.dataField=="endTime" || gridListData.dataField=="participationRate")))

               

              ) {

              adg.validateNow();

               

              return;

              }

               

               

              if ( (adg.dataProvider.length-1) != rowIndex || !isNew

              || gridListData.dataField==

              "participationRate" || gridListData.dataField=="urgency" || stratindropdown == "VWAP") {

               

              indVis =

              false;

              indIncludeInLayout=

              false;

              adg.validateNow();

              }

               

              }

               

              <mx:Label id="dlabel" width="100%"/>

               

              <mx:Label id="ind" visible="{indVis}" includeInLayout="{indIncludeInLayout}" text="+" click="changeToEditableState()"/>

              </mx:HBox>

               

              • 4. Re: Applying an item renderer when a newly added row is visible
                vcbcpna3465 Level 1

                i take that back.  Row index doesn't seem to be the issue.  The set data rendering logic is correct.  It just doesn't seem to be applied.

                • 5. Re: Applying an item renderer when a newly added row is visible
                  vcbcpna3465 Level 1

                  ok i tracked down the problem.  It seems like indVis and includeInLayout were never reinitialized to true.

                   

                  Thanks for the help.