Select to view content in your preferred language

Qualify field names in action script/xml

1179
7
04-11-2011 08:12 AM
ChrisMahon
Emerging Contributor
Hello,

I'm trying to build a tool that extracts information from a feature layer attribute table that has a joined table and i'm trying extract certain fields into a DataGrid for the end user to see and use.

I'm using ArcGIS Server Workgroup and flash builder to build my flex application.

I'm stuck however on getting the attributes into the data grid.  My Parcels Layer is a field base geodatabase called -Parcels-, and i've joined to a SQL table (sql server express) called -LinkedTable-

I'm adding the attributes to the data grid through code/action script (below) but i can't get the attributes into my data grid.  The xml at the bottom is how i'm creating the datagrid.

If i were to switch layers and use one that does not have a table join I'm able to get this to work - however when the field is joined to a table i'm unable to figure out how to properly qualify the table field names...?  Any ideas


arrayResults.addItem(graphic.attributes);   //this takes the attributes from the graphic, but the datagrid datafield isn't connecting with Parcels.ARN
//arrayResults.addItem(graphic.id.toString());  //this forces the text into the data grid - band aid solution and a round about way


  <mx:DataGrid id="resultsGrid"
      width="100%" height="170" top="25" fontSize="9" allowMultipleSelection="true"   >
  
   <mx:columns>
   
    <mx:DataGridColumn dataField="Parcels.ARN" headerText="Roll Number"    />
    <mx:DataGridColumn dataField="LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullName" headerText="Name" wordWrap="true"  />
    <mx:DataGridColumn dataField="LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.ASYSTcivic" headerText="Asyst Civic A." visible="false" id="cadd" />
    <mx:DataGridColumn dataField="LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullMailingLabel" headerText="Mailing Address" wordWrap="true"/>
    <mx:DataGridColumn dataField="LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.HomePhone" headerText="Home Phone" wordWrap="true" visible="true"/>

   </mx:columns>
  
  
  </mx:DataGrid>
Tags (2)
0 Kudos
7 Replies
DasaPaddock
Esri Regular Contributor
Try using this:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/dataGridClasses/DataG...

e.g.

private function labelFunction(item:Object, column:DataGridColumn):String
{
    return item["LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullName"];
}
0 Kudos
ChrisMahon
Emerging Contributor
How do I get this function to fire...?
I tried this
<mx:DataGridColumn id="rnc" dataField="labelFunction('LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullName',rnc);" headerText="Roll_Number"    />

No luck?



Try using this:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/dataGridClasses/DataG...

e.g.

private function labelFunction(item:Object, column:DataGridColumn):String
{
    return item["LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullName"];
}
0 Kudos
DasaPaddock
Esri Regular Contributor
Try:

<mx:DataGridColumn id="rnc" labelFunction="labelFunction" headerText="Roll_Number" />


labelFunction is a property of DataGridColumn. It should be set to the name of the function, so it could also be:
labelFunction="myLabelFunction" if myLabelFunction was the function name.
0 Kudos
ChrisMahon
Emerging Contributor
Great!

Thanks - it works now perfectly




Try:

<mx:DataGridColumn id="rnc" labelFunction="labelFunction" headerText="Roll_Number" />


labelFunction is a property of DataGridColumn. It should be set to the name of the function, so it could also be:
labelFunction="myLabelFunction" if myLabelFunction was the function name.
0 Kudos
MarkHoyland
Frequent Contributor
Thanks Dasa, This is great.
I was needing this for my selection widget.

Chris, A few things to consider.
Sorting of the fields is not available when using a labelFunction without the datafield. To fix this you can add a custom sortComapre function.
If you have lots of fields you would have to create labelFunctions and sortCompare functions for each field, so creating a more reusable solution would be a better approach.

Here is my reusable approach. Feel free to use it.
private function labelOf(fullfieldname:String):Function
{
 return  function (item:Object, column:DataGridColumn):String 
   { 
    return item[fullfieldname];
   };
}

private function sortOf(fullfieldname:String):Function 
{  
 return function (obj1:Object, obj2:Object):int 
   {  
    if(obj1[fullfieldname] < obj2[fullfieldname]) 
    {  
     return -1;
    }
    else if(obj1[fullfieldname] > obj2[fullfieldname])
    {
     return 1;  
    }
    else 
    {  
     return 0;  
    } 
   };
}

<mx:DataGridColumn headerText="Roll Number" 
 labelFunction="{labelOf('Parcels.ARN')}" sortCompareFunction="{sortOf('Parcels.ARN')}"/>
<mx:DataGridColumn headerText="Name" wordWrap="true"
 labelFunction="{labelOf('LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullName')"}
 sortCompareFunction="{sortOf('LinkedTable.dbo.ASYST_NamesTable_PrimaryOnly.FullName')}"/>

0 Kudos
DasaPaddock
Esri Regular Contributor
Mark,

You may be able to only have one label function if you make use of the column that's passed in. In the mxml you could set the dataField on the column and refer to that in the label function.
0 Kudos
ChrisMahon
Emerging Contributor
Thanks every one.  I've used the suggestions to the last two posts and things are cleaned up nicely.  My Problem is solved.

Have a great day!


Mark,

You may be able to only have one label function if you make use of the column that's passed in. In the mxml you could set the dataField on the column and refer to that in the label function.
0 Kudos