Solved! Go to Solution.
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" pageTitle="Query Task (without a map)"> <!-- This sample shows how to query the server and displaying the result in a datagrid. The query is sent using the execute() method on a QueryTask. This sample sets up a QueryTask (what layer on what server to query). When the user clicks the "Get Details" button, a Query is sent with the user-provided text to search for. Meanwhile a DataGrid has been created which listens for the results (using executeLastResult) from the querytask. --> <s:layout> <s:VerticalLayout horizontalAlign="center" paddingTop="25"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.tasks.QueryTask; import com.esri.ags.tasks.supportClasses.Query; [Bindable] public var queryTask:QueryTask; protected function button1_clickHandler(event:MouseEvent):void { // Set up the query var query:Query = new Query; query.outFields = ["STATE_NAME","STATE_FIPS","SUB_REGION","STATE_ABBR","POP2000","POP2007"] query.returnGeometry = false; query.text = stateName.text; //Use the bindable querytask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5") queryTask.useAMF = false; queryTask.execute(query); } ]]> </fx:Script> <fx:Declarations> <!--<esri:QueryTask id="queryTask" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" useAMF="false"/> <esri:Query id="query" outFields="[STATE_NAME,STATE_FIPS,SUB_REGION,STATE_ABBR,POP2000,POP2007]" returnGeometry="false" text="{stateName.text}"/>--> </fx:Declarations> <s:Panel title="Using Query tasks without maps"> <s:layout> <s:VerticalLayout/> </s:layout> <s:HGroup verticalAlign="middle"> <s:Label text="US state name: "/> <s:TextInput id="stateName" text="Carolina"/> <s:Button click="button1_clickHandler(event)" label="Get Details"/> </s:HGroup> <mx:DataGrid id="resultsGrid" dataProvider="{queryTask.executeLastResult.attributes}" visible="{queryTask.executeLastResult != null}"> <mx:columns> <mx:DataGridColumn dataField="STATE_NAME" headerText="State Name"/> <mx:DataGridColumn dataField="SUB_REGION" headerText="Region"/> <mx:DataGridColumn dataField="STATE_FIPS" headerText="FIPS"/> <mx:DataGridColumn dataField="STATE_ABBR" headerText="Abbreviation"/> <mx:DataGridColumn dataField="POP2000" headerText="Population 2000"/> <mx:DataGridColumn dataField="POP2007" headerText="Population 2007"/> </mx:columns> </mx:DataGrid> </s:Panel> </s:Application>
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" pageTitle="Query Task (without a map)"> <!-- This sample shows how to query the server and displaying the result in a datagrid. The query is sent using the execute() method on a QueryTask. This sample sets up a QueryTask (what layer on what server to query). When the user clicks the "Get Details" button, a Query is sent with the user-provided text to search for. Meanwhile a DataGrid has been created which listens for the results (using executeLastResult) from the querytask. --> <s:layout> <s:VerticalLayout horizontalAlign="center" paddingTop="25"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.tasks.QueryTask; import com.esri.ags.tasks.supportClasses.Query; [Bindable] public var queryTask:QueryTask; protected function button1_clickHandler(event:MouseEvent):void { // Set up the query var query:Query = new Query; query.outFields = ["STATE_NAME","STATE_FIPS","SUB_REGION","STATE_ABBR","POP2000","POP2007"] query.returnGeometry = false; query.text = stateName.text; //Use the bindable querytask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5") queryTask.useAMF = false; queryTask.execute(query); } ]]> </fx:Script> <fx:Declarations> <!--<esri:QueryTask id="queryTask" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" useAMF="false"/> <esri:Query id="query" outFields="[STATE_NAME,STATE_FIPS,SUB_REGION,STATE_ABBR,POP2000,POP2007]" returnGeometry="false" text="{stateName.text}"/>--> </fx:Declarations> <s:Panel title="Using Query tasks without maps"> <s:layout> <s:VerticalLayout/> </s:layout> <s:HGroup verticalAlign="middle"> <s:Label text="US state name: "/> <s:TextInput id="stateName" text="Carolina"/> <s:Button click="button1_clickHandler(event)" label="Get Details"/> </s:HGroup> <mx:DataGrid id="resultsGrid" dataProvider="{queryTask.executeLastResult.attributes}" visible="{queryTask.executeLastResult != null}"> <mx:columns> <mx:DataGridColumn dataField="STATE_NAME" headerText="State Name"/> <mx:DataGridColumn dataField="SUB_REGION" headerText="Region"/> <mx:DataGridColumn dataField="STATE_FIPS" headerText="FIPS"/> <mx:DataGridColumn dataField="STATE_ABBR" headerText="Abbreviation"/> <mx:DataGridColumn dataField="POP2000" headerText="Population 2000"/> <mx:DataGridColumn dataField="POP2007" headerText="Population 2007"/> </mx:columns> </mx:DataGrid> </s:Panel> </s:Application>