[flexcoders] Re: How to populate an attribute value in DataGrid control?

2006-05-26 Thread flexnewbie



Tracy,

Thank you very much!! It works!

--- In flexcoders@yahoogroups.com, Gordon Smith [EMAIL PROTECTED] wrote:

 Isn't it kind of strange to give your attributes names starting 
with an
 @ sign? I don't think that's common in XML, unless its use is 
dictated
 by somebody else.
 
 Also, there's no point in building up an XML string with the + 
operator.
 You can use XML literal syntax in AS3:
 
 private var gXMLDoc:XML =
 records
 record
 ...
 /records;
 
 - Gordon
 
 -Original Message-
 From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
 Behalf Of Tracy Spratt
 Sent: Thursday, May 25, 2006 4:30 PM
 To: flexcoders@yahoogroups.com
 Subject: RE: [flexcoders] Re: How to populate an attribute value in
 DataGrid control?
 
 First, the sample xml in your post is not valid: the data nodes 
have no
 closing taqs (or /). If we fix that then the example below works 
for
 your xml.
 
 The key is to use the attribute method instead of the @ symbol 
to
 reference the attributes.
 
 Tracy
 
 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
 layout=absolute 
   creationComplete=initApp()
 
 mx:Script![CDATA[
 import mx.controls.dataGridClasses.DataGridColumn;
  private var gXMLDoc:XML;
  private function initApp():void
  {
 
   var sXMLDoc:String = 
 'records' +
 'record' +
 'data @name=firstname @value=My_FirstName1 /' +
 'data @name=lastname @value=My_LastName1 /' +
 '/record' +
 'record' +
 'data @name=firstname @value=My_FirstName2 /' + 
 'data @name=lastname @value=My_LastName2 /' + 
 '/record' + 
 '/records'
 gXMLDoc = XML(sXMLDoc);
 dg1.dataProvider = gXMLDoc.record; 
  }//initApp
  
  private function lfnGeneral(xmlItem:XML,
 column:DataGridColumn):String
  {
   var sLabel:String = ;
   var sHeaderText:String = column.headerText;
   switch (sHeaderText) {
   case First Name:
   sLabel = xmlItem.data[0].attribute(@value);
   break;
   case Last Name:
   sLabel = xmlItem.data[1].attribute(@value);
   break;
   }
 
   return sLabel;
  }//lfGeneral
 
 ]]/mx:Script
 
  mx:DataGrid id=dg1 labelFunction=lfnGeneral
 mx:columns
 mx:Array
 mx:DataGridColumn headerText=First Name /
 mx:DataGridColumn headerText=Last Name /
 /mx:Array
 /mx:columns
 /mx:DataGrid
 /mx:Application
 
 
 
 -Original Message-
 From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
 Behalf Of flexnewbie
 Sent: Thursday, May 25, 2006 5:39 PM
 To: flexcoders@yahoogroups.com
 Subject: [flexcoders] Re: How to populate an attribute value in 
DataGrid
 control?
 
 Tracy,
 
 Thanks for the feedback.
 
 Unfortunately I cannot change the XML, the data is from third party 
 provider. I tried it with labelFunction and @@, it does not work :-(
 
 var sFirstName:String = xmlRecord.data[0].(@@name ==
 lastname).@@value;
 
 
 --- In flexcoders@yahoogroups.com, Tracy Spratt tspratt@ wrote:
 
  First, the @ in fornt of all the xml attributes might cause a 
 problem.
  
  Second, The name/value pair structure of your xml is going to be
  difficult to work with. Are you stuck with that structure?
  
  If so you will need to use a labelFunction(). In that you will do
  something like:
  
  var sFirstName:String = xmlRecord.data[0].(@@name ==
  lastname).@@value; //that is where those @ signe might cause a
  problem.
  
  If you can change the xml format this can be much easier.
  
  Below is a sample app that uses labelFunction on fairly complex 
xml.
  
  Tracy
  
  ?xml version=1.0 encoding=utf-8?
  mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
  layout=absolute 
creationComplete=initApp()
  
  mx:Script![CDATA[
  import mx.controls.dataGridClasses.DataGridColumn;
   private var gXMLDoc:XML;
   private function initApp():void
   {
gXMLDoc = 
  users
  user
  username gender=maleJoe/username
  useremailjoe@/useremail
  location id=001
  cityBedford/city
  stateMA/state
  /location
  /user
  user
  username gender=femaleMaggie/username
  useremailmaggie@/useremail
  location id=002
  cityLexington/city
  stateMA/state
  /location
  /user
  /users
  dg1.dataProvider = gXMLDoc.user; 
   }//initApp
   
   private function lfnGeneral(item:Object,
  column:DataGridColumn):String
   {
var sLabel:String = 
var sHeaderText:String = column.headerText
switch (sHeaderText) {
case Name:
sLabel = item.username;
break;
case Email:
sLabel = item.useremail;
break;
case City:
sLabel = item.location.city;
break;
case State:
sLabel = item.location.city;
break;
case Gender:
sLabel = [EMAIL PROTECTED];
break;
}
  
return sLabel;
   }//lfGeneral
  
  ]]/mx:Script
  
   mx:DataGrid id=dg1 labelFunction=lfnGeneral
  mx:columns
  mx:Array
  mx:DataGridColumn headerText=Name /
  mx:DataGridColumn headerText=Email /
  mx:DataGridColumn headerText=City /
  mx:DataGridColumn headerText=State /
  mx:DataGridColumn headerText=Gender /
  /mx:Array
  /mx:columns
  /mx:DataGrid
  /mx:Application

[flexcoders] How to populate an attribute value in DataGrid control?

2006-05-25 Thread flexnewbie



I can't figure out how to populate the First Name and Last Name, 
please help!
 
For Example,
XML:
records
record
data @name=firstname @value=My_FirstName1
data @name=lastname @value=My_LastName1
/record
record
data @name=firstname @value=My_FirstName2
data @name=lastname @value=My_LastName2
/record
/records

Source Code:
mx:DataGrid id=feedRequest 
dataProvider={feedRequest.result.records.record}
mx:DataGridColumn headerText=FirstName dataField= /
mx:DataGridColumn headerText=LastName dataField= /
/mx:DataGrid












--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com








  
  
SPONSORED LINKS
  
  
  

Web site design development
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



  












[flexcoders] Re: How to populate an attribute value in DataGrid control?

2006-05-25 Thread flexnewbie



Tracy,

Thanks for the feedback.

Unfortunately I cannot change the XML, the data is from third party 
provider. I tried it with labelFunction and @@, it does not work :-(

var sFirstName:String = xmlRecord.data[0].(@@name ==
lastname).@@value;


--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote:

 First, the @ in fornt of all the xml attributes might cause a 
problem.
 
 Second, The name/value pair structure of your xml is going to be
 difficult to work with. Are you stuck with that structure?
 
 If so you will need to use a labelFunction(). In that you will do
 something like:
 
 var sFirstName:String = xmlRecord.data[0].(@@name ==
 lastname).@@value; //that is where those @ signe might cause a
 problem.
 
 If you can change the xml format this can be much easier.
 
 Below is a sample app that uses labelFunction on fairly complex xml.
 
 Tracy
 
 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml
 layout=absolute 
   creationComplete=initApp()
 
 mx:Script![CDATA[
 import mx.controls.dataGridClasses.DataGridColumn;
  private var gXMLDoc:XML;
  private function initApp():void
  {
   gXMLDoc = 
 users
 user
 username gender=maleJoe/username
 useremail[EMAIL PROTECTED]/useremail
 location id=001
 cityBedford/city
 stateMA/state
 /location
 /user
 user
 username gender=femaleMaggie/username
 useremail[EMAIL PROTECTED]/useremail
 location id=002
 cityLexington/city
 stateMA/state
 /location
 /user
 /users
 dg1.dataProvider = gXMLDoc.user; 
  }//initApp
  
  private function lfnGeneral(item:Object,
 column:DataGridColumn):String
  {
   var sLabel:String = 
   var sHeaderText:String = column.headerText
   switch (sHeaderText) {
   case Name:
   sLabel = item.username;
   break;
   case Email:
   sLabel = item.useremail;
   break;
   case City:
   sLabel = item.location.city;
   break;
   case State:
   sLabel = item.location.city;
   break;
   case Gender:
   sLabel = [EMAIL PROTECTED];
   break;
   }
 
   return sLabel;
  }//lfGeneral
 
 ]]/mx:Script
 
  mx:DataGrid id=dg1 labelFunction=lfnGeneral
 mx:columns
 mx:Array
 mx:DataGridColumn headerText=Name /
 mx:DataGridColumn headerText=Email /
 mx:DataGridColumn headerText=City /
 mx:DataGridColumn headerText=State /
 mx:DataGridColumn headerText=Gender /
 /mx:Array
 /mx:columns
 /mx:DataGrid
 /mx:Application
 
 
 
 -Original Message-
 From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
 Behalf Of flexnewbie
 Sent: Thursday, May 25, 2006 2:47 PM
 To: flexcoders@yahoogroups.com
 Subject: [flexcoders] How to populate an attribute value in DataGrid
 control?
 
 I can't figure out how to populate the First Name and Last 
Name, 
 please help!
 
 For Example,
 XML:
 records
 record
 data @name=firstname @value=My_FirstName1
 data @name=lastname @value=My_LastName1
 /record
 record
 data @name=firstname @value=My_FirstName2
 data @name=lastname @value=My_LastName2
 /record
 /records
 
 Source Code:
 mx:DataGrid id=feedRequest 
 dataProvider={feedRequest.result.records.record}
 mx:DataGridColumn headerText=FirstName dataField= /
 mx:DataGridColumn headerText=LastName dataField= /
 /mx:DataGrid
 
 
 
 
 
 
 
 
 
 --
 Flexcoders Mailing List
 FAQ: 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 Search Archives:
 http://www.mail-archive.com/flexcoders%40yahoogroups.com 
 Yahoo! Groups Links











--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com








  
  
SPONSORED LINKS
  
  
  

Web site design development
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.