0 Replies Latest reply on Jun 16, 2007 9:53 AM by Mongolian Beef

    dynamic dataprovider for dynamic datagridcolumns

    Mongolian Beef

      I'm running into a scenario where I need to be able to have the datagrid dataprovider loop over data dependent on the datagridcolumn. For example, I have a collection of columns containing another collection of rows:

      public class Table {
      List<Columns> columns;

      public class Columns {
      List<Rows> rows;

      Hence the number of rows and the number of columns for the table is truly dynamic. When working with Flex's datagrid, it seems like that it forces you to know the # of columns ahead of time in order for the dataprovider to be effective. I tried using dynamic columns in AS3 below:
      var dg:DataGrid = new DataGrid();
      var dgc:DataGridColumn
      var aColumnsNew:Array = dg.columns;

      var columns:ArrayCollection = ArrayCollection(table.columns);
      var column:Column;
      for (var i:int = 0; i < column.length; i++) {
      column = Column(columns.getItemAt(i));
      var rows:ArrayCollection = ArrayCollection(column.rows);
      dgc = new DataGridColumn();
      dgc.headerText = column.name;
      dgc.dataField = "value"

      Above, I'm creating the # of columns dynamically. However, notice that each column has its own set of rows, i.e. has its own dataprovider. I can guarantee that the number of rows will be the same for all columns so, theoretically, one dataprovider will be sufficient. However, its getting to the appropriate List<Rows> via the dataprovider is what I don't know how to do. I was thinking about changing my domain model (in java) but I still would run into a similar issue with the dataprovider. Any ideas?

      Any help would be appreciated. Thanks in advance!