2 Replies Latest reply on Feb 6, 2008 2:57 PM by ebrentnelson

    DataGrid renderer dynamic columns

    Greg_Simons
      I am new to flex and have been impressed with the components and been converted from Open Laszlo.

      However I have a data provider that returns xml and I have no idea what the columns are going to be. So potentially I could need a checkbox and not know the column name, so I cant create the mapping with the datagridcolumn because I dont know the name, I know the type of field from the JSP.

      Also if i did use datagridcolumn to map to a field name, it doesnt display the other columns because I havent added them in to the column tag. Is there any way to get the other columns to display without adding them to the datagridcolumns mapping as I dont know what these are going to be at runtime because they are dynamic.

      Thanks
      Greg
        • 1. Re: DataGrid renderer dynamic columns
          peterent Level 2
          It sounds like you just want to know how to add columns dynamically. As you loop through your XML data set you can add columns to the DataGrid:

          var columnArray:Array = new Array();

          var dc:DataGridColumn = new DataGridColumn();
          dc.headerText = "something from your xml data";
          dc.dataField = "something from your xml data";
          // any other properties to set
          columnArray.push( dc );
          .. continue you loop ...

          Now assign the Array of DataGridColumns to the DataGrid.
          grid.columns = columnArray;
          • 2. DataGrid renderer dynamic columns
            ebrentnelson Level 1
            You can also use the listData variable to get the data from the specified dataField (set in the DataGridColumn)