Skip to main content
January 10, 2013
Answered

Load directly from php as DataProvider for datagrid

  • January 10, 2013
  • 2 replies
  • 829 views

Hi

The normal method to load data from php in to a datgrid is to push it into and array first...:

for(var i:uint=0; i<event.target.data.dgRows; i++)

{

                dgArr.push

                ({

                                id:event.target.data["id"+i],

                                dateLogged:event.target.data["dateLogged"+i],

                                quoteNumber:event.target.data["quoteNumber"+i],

                                clientPoNum:event.target.data["clientPoNum"+i],              

                                compName:event.target.data["compName"+i],               

                                exclusive:event.target.data["exclusive"+i],              

                                TAX:event.target.data["TAX"+i],           

                                inclusive:event.target.data["inclusive"+i]

                });

}

DG1.dataProvider = new DataProvider(dgArr);

What I'd like to know is if it is possible to pass "event.target.data" directly as a dataprovider, tried this but didn't work for obvious reasons: DG1.dataProvider = new DataProvider(event.target.data);

Basically I want code that doesn't have to change for each php file and reduce the amount of coding lines  eg. I want to eliminate\change to 'dynamic':

"for(var i:uint=0; i<event.target.data.dgRows; i++) {dgArr.push({ ....... });"

Something like this would be awesome...

for(var key:String in map)

{

                dgArr.push

                ({

                       key : map[key]

                });

}

(the above code will add a row for each key which actually represent a column which is totally not what is required and is empty because the "key" must indicate.... )

Help will be appriciated

This topic has been closed for replies.
Correct answer sinious

You can use the native JSON encoding functions in PHP to wrap your results in an object that can use the native JSON decoding functions in AS3 to turn it back into an array which can be used as a dataProvider.

You can also of course write the logic to wrap your results in XML from PHP and use that directly as a dataProvider.

Just set the proper MIME type for what you're sending and use normal string receive mode. e.g. return as XML and myGrid.dataProvider = XML(e.target.data); or return JSON and myGrid.dataProvider = JSON.parse(e.target.data);

edit:

Haha do you ever sleep kglad..

2 replies

sinious
siniousCorrect answer
Legend
January 10, 2013

You can use the native JSON encoding functions in PHP to wrap your results in an object that can use the native JSON decoding functions in AS3 to turn it back into an array which can be used as a dataProvider.

You can also of course write the logic to wrap your results in XML from PHP and use that directly as a dataProvider.

Just set the proper MIME type for what you're sending and use normal string receive mode. e.g. return as XML and myGrid.dataProvider = XML(e.target.data); or return JSON and myGrid.dataProvider = JSON.parse(e.target.data);

edit:

Haha do you ever sleep kglad..

kglad
Community Expert
Community Expert
January 10, 2013

(yes, but i awaken early.  it's the curse of being an md.  even when i don't have to do anything in the morning, i still am unable to sleep-in.  but i can sure fall asleep watching tv at just about any time.)

January 11, 2013

lol - I've often wondered that my self - thanks a mil to both you guys, awesome as alway!!

kglad
Community Expert
Community Expert
January 10, 2013

yes, if your php returned the data in an appropriate xml format.