Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Load directly from php as DataProvider for datagrid

Guest
Jan 10, 2013 Jan 10, 2013

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

TOPICS
ActionScript
756
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 10, 2013 Jan 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

...
Translate
Community Expert ,
Jan 10, 2013 Jan 10, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2013 Jan 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..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2013 Jan 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.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 10, 2013 Jan 10, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2013 Jan 11, 2013

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 11, 2013 Jan 11, 2013
LATEST

You're welcome and good luck! (I for the record would go JSON as there's native encoders on both sides making it really, really easy).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines