4 Replies Latest reply on Nov 11, 2009 10:14 AM by =VA=FyreHeart

    Dynamic Datagrid

      I would like to create a dynamic datagrid in actionscript.

      The reason being that I will not know until runtime exactly how many datacolumns I will have as the data is dynamic.

      I can't seem to find any online examples on how to accomplish this.

      All help gratefully received

        • 1. Re: Dynamic Datagrid
          I would imagine that you would simply create the appropriate DataGridColumns at runtime, in accordance with how many you need. What exactly do you need help with? How far have you gotten? What seems to be the stumbling block?
          • 2. Dynamic Datagrid
            Here a snippet of what I use in my code

            private function buildDG(fieldArray:Array):void{
            for(var index:Number=0 ; index<fieldArray.length ; index++){
            var thisDGC:DataGridColumn = new DataGridColumn();
            thisDGC.dataField = String(fieldArray[index]).dataField;
            thisDGC.headerText = String(fieldArray[index]).labelField;

            var tempCols:Array = new Array();

            You'll have to have knowledge of your data column names, and the header labels you want to use. Also if you want to add custom renderers and sort functions you'll need to do something like this:

            thisDGC.itemRenderer = new ClassFactory(myRenderer);
            thisDGC.sortCompareFunction = mySortFunction;

            if you don't have knowledge of the column names you can loop over a single data item like this:

            var colNames:Array = new Array();
            for(var item:Object in myData.getItemAt(0)){
            • 3. Re: Dynamic Datagrid
              jonrmayer Level 1
              Cheers Thanx for this code: I'd somehow managed to create my own - with a lot of code!! - this is much simpler

              Thank you
              • 4. Re: Dynamic Datagrid
                =VA=FyreHeart Level 2

                Thanks ur_dtrain. This has been a huge help.