0 Replies Latest reply on Dec 16, 2007 3:44 AM by Ruben Ramirez

    DataGridColumn- dynamic columns

    Ruben Ramirez Level 1
      I've been having problems editing data on a datagrid. My dataProvider is an array of objects and within that object I have a hashtable of objects that I want to display on the grid as a row. Now this hashtable might contain one or more items. When I set the dataProvider I create the fixed DataGridColumns and then I start creating the dynamic ones.

      I extended DataGridColumn so I can add the column information that I need in order to retrieve the data for that column.
      I add an itemRenderer as follows:

      <mx:Component id="txtScoreRenderer">
      <mx:Label name="name" text="{outerDocument.getDataForColumn(data,listData)}" />
      </mx:Component>

      Then my method that retrieves each cell is:

      public function getDataForColumn(data:Object,listData:Object):String{
      if (data==null) return "";
      var dg:DataGrid = (listData) ? DataGrid(listData.owner) : null;

      var column:AssignmentDataGridColumn = (dg) ? dg.columns[listData.columnIndex] as AssignmentDataGridColumn : null;

      var classStudentLink:ClassStudentLink=data as ClassStudentLink;
      var studentScore:StudentScore=classStudentLink.getScore(column.assignment.id);
      return studentScore.pointsEarned;
      }

      The method classStudentLink.getScore(column.assignment.id) is what goes into the hashtable and retrieves the data for that cell. My problem is when I try to edit the column. When I click on the column it goes to the last item on the cell and then when I click out of it I get:

      ReferenceError: Error #1069: Property null not found on com.ivmath.lp.bo.gb.ClassStudentLink and there is no default value.

      Now I can't set the dataField on the datagridColumn because the property doesn't exist on the class since the columns are dynamically created which is why I use a hashtable.

      Any help would be greatly appreciated.
      Ruben