header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Dinesh
Points:0
Posts:0

5/10/2010 5:13:03 AM

Title: Generating Datagrid column dynamically


We need to generate the datagrid column dynamically according to the selection of table in the combobox(it consists list of tables in database)

The tables contain different no of fields..
According to the no of fields, columns should be generated..
The no of fields should be get from the php file..that is not a problem..

Now the prolem is generating the columns dynamically..





private function readdata():void
  {
   var obs:Object=new Object();
   obs.names=db_cmb.text;      //database name
   obs.tabname=table_cmb.text; //table name
  
   adhttp.method="POST";
   adhttp.url="http://localhost/general_comp/read_data.php"; //This php file works fine and it produce the result clearly..
   adhttp.useProxy=false;
   adhttp.resultFormat="e4x";
   adhttp.addEventListener("result",getdatax);
   
   dg.visible=false;
   dg.includeInLayout=false;
   adhttp.send(obs); //send object to above url (it will return entire data in the table)
   Alert.show("1"); //just for check
  }
   
  private function getdatax(geteve:ResultEvent):void
  {
             dg_xml = geteve.result as XML;
             dg_xml_list = new XMLListCollection(geteve.result.getcol); //getcol is tag name in php file
             buildDG();
}
  
  private function buildDG():void
  {
    var aColumnDef:Array = getColumnDefArray();                
       var oColumnDef:Object;
       dg=new DataGrid();
       var dgc:DataGridColumn;
       var aColumnsNew:Array = dg.columns;
      // var iTotalDGWidth:int = 0;
       for (var i:int=0;i<aColumnDef.length;i++)  
      {
         oColumnDef = aColumnDef[i];
         dgc = new DataGridColumn();            
         dgc.dataField = oColumnDef.dataField;  
         aColumnsNew.push(dgc)                  
      }
      dg.setStyle("color","#0F1151");
      dg.columns = aColumnsNew;
      dg.rowCount=dg_xml.children().length()+1;
      dg.y=150;           
      dg.dataProvider = dg_xml_list;
      dg.visible=true;
      dg.includeInLayout=true;          
     application.addChildAt(dg,0);     
      
     //  dg.addEventListener(ListEvent.ITEM_CLICK,listclient); //here we have a doubt
  }
  
  private function getColumnDefArray():Array
   {
       var aColumns:Array = new Array();
       var node0:XML = dg_xml.getcol[0];                        
       var xlColumns:XMLList = node0.children();                     
       var xmlColumn:XML
       var oColumnDef:Object;
       for (var i:int=0;i<xlColumns.length();i++)  {                   
         xmlColumn = xlColumns[i];
         oColumnDef = new Object();
         oColumnDef.dataField = xmlColumn.localName();                  
        aColumns.push(oColumnDef);
       }
       return aColumns;           
    }





1
Friend
Points: 710
Posts:0
5/10/2010 5:40:30 AM



you can use addDataGridColumn("colName"); to add a new column to dataGrid any time. To add the data also you need to update the data provider.

2
Friend
Points: 710
Posts:0
5/10/2010 5:49:00 AM



sorry forget to post the above method

private function addDataGridColumn(columnField:String):void {
		var newColum:DataGridColumn = new DataGridColumn(columnField);
		var allcolumns:Array = myDataGrid.columns;
		allcolumns.push(newColum);
		myDataGrid.columns = allcolumns;
	}

3
Dinesh
Points: 0
Posts:0
5/10/2010 10:24:55 AM



Accepted..

Thank u..


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 2+7 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions