3 Replies Latest reply on Jul 24, 2009 1:59 PM by Gregory Lafrance

    Datagrid won't populate with 1 record.

    SushiSnacks Level 1

      Hey I call a HTTPService dynamically to populate a datagrid. If the HTTPService returns more than 1 row, everything shows fine, but if it only returns 1 row (1 "bug" children below), nothing happens.

       

      On the same page I have a mx:list with the same dataprovider to see what was going on.. and that only gets populated when 1 row is returned.

       

      Am I missing something like if 1 row is returned then it won't be an Array Collection?

       

      here is a sample of 1 row.

       

      <?xml version="1.0" encoding="utf-8" standalone="yes"?>
      <bugs>
           <bug>
                <id>51</id>
           <desc>Bug Tracker System @</desc>
           <bugDesc>Send Emails when a bug is added or edited.</bugDesc>
            </bug>
      </bugs>
                

      Thanks!

        • 1. Re: Datagrid won't populate with 1 record.
          Gregory Lafrance Level 6

          You might be better off using an XMLListCollection.

           

          If this post answered your question or helped, please mark it as such.

          1 person found this helpful
          • 2. Re: Datagrid won't populate with 1 record.
            SushiSnacks Level 1

            I found the solution. If the XML returns 1 child, then it won't be type "ArrayCollection", but "ObjectProxy", so adding this to the resultHandler function fixes it

                        import mx.utils.ArrayUtil;

                        private function resultHandler(event:ResultEvent):void {
                            if(event.result.bugs.bug is ArrayCollection){ 
                                myData = event.result.bugs.bug;
                            }else if(event.result.bugs.bug is ObjectProxy){
                                myData = new ArrayCollection(ArrayUtil.toArray(event.result.bugs.bug));
                            }
                        }

             

             

            Thanks for the tip, but would you please tell me why it'd be better to use XMLListCollection?

            jd.

            • 3. Re: Datagrid won't populate with 1 record.
              Gregory Lafrance Level 6

              I've used HTTPService to return XML data, and sometimes the data has only one item. I use e4x as the resultFormat, and XMLListCollection and it seems to work fine.