View Full Version : When you use an editable datagrid...
Scuba_Steve
06-28-2007, 09:14 PM
do your changes automatically change the dataProvider?
I would think so, since the datagrid is just a way to display the dataProvider (in my case, an array), but I just want to verify. :cool:
LOLFlash
06-28-2007, 09:36 PM
swf it is an Array in Array in Array.......
Scuba_Steve
06-28-2007, 09:52 PM
say what? i was looking more for either a "yes" or a "no, you see actually what happens is...". :)
LOLFlash
06-28-2007, 10:17 PM
I would say no
demerit
08-07-2007, 09:38 PM
I've been searching all day for this information. Been reading through liveDocs as well...
From what I understand (very poorly at best) is that once you push your array into the dataGrid, the component re-structures or re-formats the data for its purposes. So, when you go to change a field, it's not updating the original array you pushed (because it's no longer bound to that source of data).
In my case, I'm trying to create a shopping cart where you can update the quantity of a product and it updates the shopping cart's array. Sounds simple enough, eh?
1. Some suggest adding a binding in the component to your DataProvider (in my case, my array). I tried this using the component inspector window, but couldn't figure out how/where to reference/select my array.
2. Others suggest that you have to use the field's associated data to search for the item in the array and update it "manually". What I mean is that if the product that I'm updating in the grid has an item number of sp-50 and I change the quantity from 2 to 1, then I have to write code that senses the change I made, recognizes that the change is being made to the item sp-50, searches for that in the array (using sp-50 as the key), and updates its associated quantity with the new number.
Otherwise if you loop through the array using the standard keys (e.g., "0, 1, 2, 3, 4...") and the array's order doesn't match the component's order, then you run the risk of changing the quantity for the wrong item.
Could somebody in-the-know rate the severity of my confusion?
I mean, seriously:
array (i.e., DataProvider) -> dataGrid | dataGrid change -> array (i.e., Data Provider)
seems so simple.
Is #1 or #2 closer to the right track? Could ya help a nephew out and point me in the general vicinity of the right direction?
:confused:
demerit
08-07-2007, 11:28 PM
This is how I've got it set up (granted the rest of the code for my website is missing, but you get the idea)...
My "Add to Cart" buttons:
isbutton.onRelease = function() {
addedproduct = thumbnails[k]; //thumbnails[k] is an array containing the product numbers
addedprice = price[k]; //price[k] is an array containing prices (spluh)
if (theBasket[addedproduct] == undefined) {
theBasket[addedproduct] = {itemname:[addedproduct], price:addedprice, quantity:1};
updateDatagrid();
} else {
theBasket[addedproduct].quantity++;
updateDatagrid();
}
My updateDatagrid function:
function updateDatagrid():Void {
var theCart:Array = new Array();
totalPrice = 0;
for (var e in theBasket) {
if (theBasket[e].quantity>0) {
myprice = theBasket[e].price;
myquantity = theBasket[e].quantity;
theCart.push({Product:theBasket[e].itemname, Quantity:theBasket[e].quantity, Price:(theBasket[e].price*theBasket[e].quantity)});
totalPrice += theBasket[e].quantity*theBasket[e].price;
}
}
Some code initializing the dataGrid component:
shoppingcart_mc.basketInfo.dataProvider = theCart;
_root.shoppingcart_mc.basketInfo.getColumnAt(0).ed itable = false;
_root.shoppingcart_mc.basketInfo.getColumnAt(2).ed itable = false;
shoppingcart_mc.basketInfo.vScrollPolicy = "auto";
shoppingcart_mc.tTotal.text = totalPrice;
And a listener set up to detect the changes, update the quantity in the original array, and then update the dataGrid once more:
var myListener = new Object();
myListener.cellEdit = function(event) {
cell = event.itemIndex;
changedproduct = _root.shoppingcart_mc.basketInfo.getItemAt(cell).P roduct;
theBasket[changedproduct].quantity = _root.shoppingcart_mc.basketInfo.getItemAt(cell).Q uantity;
updateDatagrid();
};
_root.shoppingcart_mc.basketInfo.addEventListener("cellEdit",myListener);
Hope this helps...
sherry
11-04-2007, 04:29 PM
hi,
i have a peice of code in C and OpenGl which shows a waving flag (if you type wave.c in google you can see the code) i have to use this code in my final year project as a base to simulate the waves on a sea seen from a aircraft (sea-state flight simulator). ok this was just an introductory.
there is a simulator in the university which has an update rate of 50 Hz which means it takes it 20 ms after each code execution to show the animation on the screen. how do i adjust this peice of code to this update frequency of 50 Hz? could anyone help me with this plz.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.