
Populate the DataGrid component 213
Populate the DataGrid component
You want to use the DataGrid control to display the data returned by the web service.
Specifically, you want to display the titles of the most popular posts and the number of clicks
each has received.
1. In Source mode, enter the following dataProvider property in the <mx:DataGrid> tag
(in bold):
<mx:DataGrid x="30" y="75" id="dgTopPosts" width="400"
dataProvider="{wsBlogAggr.getMostPopularPosts.lastResult}">
You want to display the results of the web service’s getMostPopularPosts operation in the
DataGrid control.
2. In the first <mx:DataGridColumn> tag, enter the following headerText and dataField
property values (in bold):
<mx:DataGridColumn headerText="Top Posts" dataField="postTitle" />
You want the first column in the DataGrid control to display the titles of the posts. You do
this by identifying the field returned by the web service operation that contains the title
data, and then entering the field name as the value of the
dataField property. According
to the API documentation for the
getMostPopularPosts method, the field called
postTitle contains the information you want.
3. In the second <mx:DataGridColumn> tag, enter the following headerText, dataField,
and
width property values (in bold):
<mx:DataGridColumn headerText="Clicks" dataField="clicks" width="75" />
You want the second column in the DataGrid control to display the number of clicks for
each post during the last 30 days. According to the API documentation, the field that
contains the data is called
clicks.
4. Delete the third <mx:DataGridColumn> tag.
You don’t need a third column.
The
<mx:DataGrid> tag should look as follows:
<mx:DataGrid x="30" y="75" id="dgTopPosts" width="400"
dataProvider="{wsBlogAggr.getMostPopularPosts.lastResult}">
<mx:columns>
<mx:DataGridColumn headerText="Top Posts" dataField="postTitle"/>
<mx:DataGridColumn headerText="Clicks" dataField="clicks"
width="75"/>
</mx:columns>
</mx:DataGrid>
Kommentare zu diesen Handbüchern