1 Reply Latest reply on Jul 30, 2007 1:39 PM by rbetieh

    Performance of  ADG Tied to number of Columns?

    rbetieh Level 1
      Hi All,

      I was wondering if there is a correlation between the time it takes for an ADG to update itself after data changes and the number of columns. I want to know in case its just my bad code :-). As an example, I notice that the ADG is much slower under 31 columns than 15 for this simple example. I am a beginner at this so I assume I dont know what I am doing, but the speed difference is an order of magnitude different.

      <mx:AdvancedDataGrid xmlns:mx=" http://www.adobe.com/2006/mxml" rowHeight="25" sortItemRenderer="SortItemHider"
      creationComplete="init()" allowMultipleSelection="true" selectionMode="singleCell" itemClick="setStart(event)" xmlns:local="*" >

      <mx:columns>
      <mx:AdvancedDataGridColumn dataField="task" id="task" headerText="task" width="60" textAlign="center" resizable="true" />
      </mx:columns>

      ...

      private function initColumns():void //This function creates a bunch of dynamic columns and adds them to the adg
      {
      var test1:Array = this.columns;
      var test2:ArrayCollection = new ArrayCollection(test1);
      test2.removeAll();
      for(var index:int = 0; index < this.columns.length; index++)
      {
      test2.addItem(this.columns[index]);
      }
      defaultColumns = test2.length - 1;
      for(var x:int = 0; x < MAX_COLS; x++)
      {
      var newColumn:AdvancedDataGridColumn = new AdvancedDataGridColumn("day"+(x+1));
      newColumn.dataField = "day"+(x+1);
      newColumn.setStyle("textAlign", "center");
      var day:Number = todaysDate.getDate();
      newColumn.headerText = String(x);
      test2.addItem(newColumn);
      }
      this.columns = test1;
      }

      ...

      private function setStart(event:ListEvent):void //when a cell that is not the first is clicked, this will set data into the adg
      {
      var task:String = event.itemRenderer.data.task;

      var selectedRow:int = dataArray.getItemIndex(event.itemRenderer.data);
      var selectedItem:Object = dataArray[selectedRow];

      var totalHours:int = selectedItem.unscheduled;
      selectedItem.unscheduled = 0;
      var startDay:int = this.selectedColumnIndex - defaultColumns;
      if(startDay > 0 && selectedRow != -1)
      {
      var HoursPerDay:int = 8;
      var dailyHours:int = totalHours / HoursPerDay;
      var leftoverHours:int = totalHours % HoursPerDay;
      var days:int = dailyHours + (leftoverHours != 0 ? 1 : 0);
      var endDay:int = startDay + days;
      selectedItem.start = startDay;
      var columnName:String;
      for( var index:int = startDay; index < endDay; index++)
      {
      columnName = "day"+index;
      if(index < this.columns.length)
      {
      if(index == endDay-1 && leftoverHours > 0)
      {
      selectedItem[columnName] = leftoverHours;
      return;
      }
      selectedItem[columnName] = HoursPerDay;
      }
      }
      }
      }
      }