Looks pretty close.  What is not working?

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Pete Appleby
Sent: Friday, December 26, 2008 1:51 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] DataGrid and XMLListCollection - newbie question

 

Hi. I am trying to get a very simple datagrid up and going. I need to
be able to populate this from an XMLListCollection. This seems very
simple, but I am obviously missing the point somewhere in this. It
seems that all of the books and online searchs show web services, etc.
as source. 

I need to be able to start at a simpler point. I have tried setting
things up both in ActionScript and mxml. The ActionScript is commented
out at this point. Either way would be fine. The best would be able to
see it work in both ways.

The purpose of this snippet is:

1. Initialize the grid with a single row. When the app starts, I have
an empty grid. I need to start with a default row in the grid.
2. Allow the user to click the Add Step button to add a new row to the
bottom of the grid.
3. Allow the user to click the Clear Steps button to remove all
existing rows and then add the default row.
4. Later in the development of this, I will extract the bound data
from the grid to create a payment schedule.

Here is the code.

Thanks!

Pete

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
layout="absolute" applicationComplete="initApp()" >
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;

/*
[Bindable]
public var gridData:XMLListCollection;

private const gridInitXML:XML =
<Steps>
<Step Payments="1" Amount="100" />
</Steps> ;
*/ 
private function initApp():void{

// initialize the data grid

// gridData = new XMLListCollection( );
// gridData.addItem( gridInitXML ); 
}

private function handleAddStep():void {
gridData.addItem(gridInitXML);
}

private function handleClearSteps():void {
gridData.removeAll();
gridData.addItem(gridInitXML);
}

]]>
</mx:Script>

<mx:XMLListCollection id="gridData" source="{Steps}" />
<mx:XMLList id="Steps" xmlns="">
<Step Payments="1" Amount="100" />
</mx:XMLList>

<mx:XML id="gridInitXML" >
<Steps>
<Step Payments="1" Amount="100" />
</Steps> 
</mx:XML>

<mx:Button x="10" y="10" label="Add Step" width="86" id="btnAddStep"
click="handleAddStep()" />
<mx:Button x="114" y="10" label="Clear Steps" width="96"
id="btnClearSteps" click="handleClearSteps()"/>

<mx:DataGrid id="dgSteps" editable="true" enabled="true"
dataProvider="{gridData}"
x="10" y="38" width="200" height="190" >
<mx:columns>
<mx:DataGridColumn headerText="Payments" dataField="Payments"
width="75" textAlign="right"/>
<mx:DataGridColumn headerText="Amount" dataField="Amount" 
textAlign="right"/>
</mx:columns>
</mx:DataGrid>

</mx:WindowedApplication>

 

Reply via email to