PDA

View Full Version : getting data out datagrid


mrka
04-24-2006, 08:19 AM
Hi,
I have a probleme since few day and didn't succes to finish my shopping cart cause i got some trouble to write good function.

I have a datagrid where item are stored (name, price, quantity)
i need to get all the data of datagrid outpouting in textarea, so i can send the list of item by mail during checkout porcess.

Actually i didn't succes to write function cause i'am bad coder

it's look like

function getallitems() {
myoutput= panier_dg.dataProvider;
for (var i = 0; i<(myoutput.length); i++) {
var currentItem = myoutput.getCurrentItem();
var subtotal = currentItem.itemtotal;
var quantity = currentItem.quantity;
var unitprice = currentItem.itemprice;
var name = currentItem.productname;

trace (myoutput);
trace(myoutput.quantity[i]);
}}

Of course not running.
I need to get it quick, i'am ready to pay people that can help me to finish this little part of code (i can send fla of course)
If you can help me i will be very thanksfull

Best regards
Stephane

mrka
04-24-2006, 09:45 AM
So i have found at 95%
Actually my result sort in combobox, somebody can help me to sort it too textarea?

THANKS :-)



/**
*
* DataGrid filter with dynamic ComboBox
* by PhilFlash : http://philflash.inway.fr
*
**/
import mx.utils.Delegate;
import mx.controls.gridclasses.DataGridColumn;
// ----- DataGrid -----
// Create columns for datagrid
personne_dg.columnNames = ["nom", "prenom", "ville"];
//customize columns
var col:mx.controls.gridclasses.DataGridColumn;
var totalWidth:Number = 0;
//
col = personne_dg.getColumnAt(0);
col.width = 150;
col.headerText = "Nom :";
totalWidth += col.width;
//
col = personne_dg.getColumnAt(1);
col.width = 150;
col.headerText = "Prénom : ";
totalWidth += col.width;
//
col = personne_dg.getColumnAt(2);
// 18: width of vertical scrollbar
col.width = personne_dg.width-(totalWidth+18);
col.headerText = "Ville :";
//
personne_dg.setStyle("alternatingRowColors", Array(0xFFFFFF, 0xF7F7F7));
//
// ----- Create dynamic ComboBox -----
//
personne_ds.addEventListener("afterLoaded", Delegate.create(this, doCreateDataTextArea));
function doCreateDataTextArea():Void {
var dataProvider:Array = personne_ds.items;
var len:Number = dataProvider.length;
var resultDP:Array = [];
for (var i:Number = 0; i<len; i++) {
var currentValueville:String = dataProvider[i].ville;
var currentValuenom:String = dataProvider[i].nom;
var currentValueprenom:String = dataProvider[i].prenom;
var found:Boolean = false;
var maxDP:Number = resultDP.length;
for (var j:Number = 0; j<maxDP; j++) {
if (resultDP[j].text == ""+currentValueville+" "+currentValuenom+" "+currentValueprenom+"") {
found = true;
break;
}
}
// Add the new value
if (!found) {
var newObject:Object = {text:""+currentValueville+" "+currentValuenom+" "+currentValueprenom+""};
resultDP.push(newObject);

}
}
// Sort result DataProvider

resultDP.sortOn("text");
// Add the first item
// set the dataProvider for comboBox
filter_cb.dataProvider = resultDP;
}
//
// ----- filter for ComboBox -----
//

//
// ----- Decode XMLConnector result -----
// Fastest method : see http://philflash.inway.fr/dgperf
//
personne_con.addEventListener("result", Delegate.create(this, doParseData));
//
// parse XML : "fastest" method
//
function doParseData():Void {
var dataXML:XML = personne_con.results;
var resultArray:Array = [];
var mainNode:XMLNode = dataXML.firstChild;
var aNode:XMLNode = mainNode.firstChild;
while (aNode) {
var obj:Object = new Object();
for (var attribute in aNode.attributes) {
obj[attribute] = aNode.attributes[attribute];
}
resultArray.push(obj);
aNode = aNode.nextSibling;
}
// -- use items (and not dataProvider)
personne_ds.items = resultArray;
}
// ----- Start application -----
personne_con.trigger();