Skip to main content
Inspiring
April 11, 2006
Question

array of objects into dataset and then to datagrid

  • April 11, 2006
  • 1 reply
  • 365 views
I have discovered amfphp ( http://amfphp.org). It's a really cool way to move complex data objects from php to flash and back.
quote:


So I am successfully creating an array of items from my database...an item that would otherwise be created like this:
items = array();
item[0] = new Object();
item[0].id = 7;
item[0].name= "Item 1";
item[0].styleNumber = "001";
item[1] = new Object();
.
.
.
etc.



I put DataSet and DataGrid objects on my stage called productDataSet and productDataGrid, respectively, and tried this:

quote:


this.productDataSet.items = re.result;
trace('dataSet length:' + this.productDataSet.getLength());
this.productDataGrid.dataProvider = this.productDataSet.dataProvider;



the trace appears to work correctly--several hundred items--and the dataGrid shows my object property names (albeit in reverse order) and the DataGrid appears to have several hundred items in it but there is NO DATA THERE. All the list items are blank.

I've had a bit of luck working with the component inspector creating bindings and stuff but I'm hampered by my incomplete understanding of how it works. All the tutorials I've found instruct me to import an XML sample to create a schema. Since I have no XML i cannot one.

I want to do just a couple of things:
1) put my data in the DataSet properly, ideally in one fell swoop--i *think* i've done this correctly above
2) attach the DataGrid to the DataSet so that when i sort or filter the data set, the datagrid shows the results and when i select an item in the DataGrid, the DataSet knows that is the currently selected item.
3) hide the 'id' field in the data grid and display user-friendly names for the columns: "Style Number" rather than "styleNumber".

Any help would be much appreciated. I *think* this is all about understanding schemas but I don't really know.
This topic has been closed for replies.

1 reply

sneakyimpAuthor
Inspiring
April 11, 2006
Just to show how serious I am, all of these tutorials mention xml:

http://livedocs.macromedia.com/flash/mx2004/main_7_2/00003750.html
http://www.flash-db.com/Tutorials/databind/CatalogTutorial.php?page=1
http://www.peterelst.com/blog/2003/11/02/using-the-databinding-api/

Can anyone refer me to a tutorial or documentation that describes binding a dataSet to a dataGridin the absence of a schema? or perhaps a schema tutorial?
Inspiring
April 11, 2006
Hi,

maybe this can give you some ideas: http://www.sephiroth.it/tutorials/flashPHP/pageable_recordset/. I'm not really into Datasets and schemas, but I noticed there's no xml involved in that tutorial.

hth,
blemmo
sneakyimpAuthor
Inspiring
April 11, 2006
That *is* a very interesting article. Unfortunately, it doesn't mention anything about DataSets. I haven't had any trouble getting my data into my flash application. I've also been able to put it into a DataGrid pretty easily (although not quite as elegantly as that example did).

The problem is that I'm having issues when I introduce a DataSet for filtering. I can't get the data from the DataSet into the DataGrid like I want it. I haven't been able to hide the 'id' column of my data and the column names unfortunately are *exactly* what the Object property names are. I was hoping to put user-friendly column headers on their like 'Product Name' rather than 'name' or 'Style Number' rather than 'styleNumber'.

Also, the concept of a schema is still somewhat beyond me. I tried changing the schema for my productDataSet to this and I got the data to display. I added 'name, 'styleNumber', and 'id'
quote:


<-->dataProvider : Array
<-->deltaPacket : DeltaPacket
<-->items : Array
<-->selectedIndex: Number
<-->name : String
<-->styleNumber: String
<-->id : Integer



I have tried radically different shemas (schemae?) that seem to also get the data in there but I don't really understand what i'm doing here and I feel like I'm asking for trouble not knowing how this stuff really works.

And, like I said before, i want to hide certain information that's in the DataSet so that it doesn't get displayed. I'd also like to Have some user-friendly names rather than the actual field/property identifiers.