4 Replies Latest reply on Apr 16, 2008 2:44 PM by nate1003

    Simple dataProvider for dataGrid question

    nate1003
      I have a question about accessing some values from an xmllist. I have a piece of xml that is returned from an httpservice that looks similar to this.

      <topnode>
      <list>
      <item>value</item>
      <item>value2</item>
      <item>value3</item>
      </list>
      </topnode>

      I'm interested in creating a datagrid to display the values of each list.item, so: value, value2, value3. I'm not sure what my data provider should look like in this case since there are no nodes underneath the repeating node.

      I can create an xml list like:
      myList = event.result.list.item
      but this gives me an xmllist with values of [0].item.value, [1].item.value etc. I'm just unsure how to setup my datagrid to extract values from the item node.

      I think if my xml looked like the following I could access it like:
      (in my httpservice result handler)
      myList = event.result as XML
      (the datagrid provider would look like)
      dataProvider={myList.item}
      (and the column would have an entry like this)
      dataField="name"


      <topnode>
      <list>
      <item>
      <name>bob</name>
      </item>
      <item>
      <name>stan</name>
      </item>
      <item>
      <name>bill</name>
      </item>
      </list>
      </topnode>

      But in my case, the value I'm extracting is the value set at the top level node that repeats. Maybe I'm missing something obvious here.
      Any thoughts?
        • 1. Simple dataProvider for dataGrid question
          ChrisBAH1008 Level 1
          Hey there,

          The following example should help you:
          someResultHandler(event:ResultEvent):void
          {
          .....
          myList = event.result.list.item
          ....
          }

          <mx:DataGrid id="dgTop" width="100%" height="100%" doubleClickEnabled="true"
          dataProvider="{myList}"
          alternatingItemColors="[#FFFFFF,#FFFFFF]">
          <mx:columns>
          <mx:DataGridColumn dataField="name" headerText="Name" width="30"/>
          </mx:columns>
          </mx:DataGrid>

          It really should be that simple. Hope this helps.

          • 2. Re: Simple dataProvider for dataGrid question
            nate1003 Level 1
            Hey, thanks for the fast reply!

            It was the first example that I was struggling with really, where the value I want to display in the dataGrid is actually the value that is shown in the element <item> which is also the repeated node. So like this:

            <topnode>
            <list>
            <item>value</item>
            <item>value2</item>
            <item>value3</item>
            </list>
            </topnode>

            So my datagrid would have the values value, value2 and value3

            Hopefully this is a stupid question. :)
            • 3. Re: Simple dataProvider for dataGrid question
              ChrisBAH1008 Level 1
              Oh okay, well in that case your resultHandler should look slightly different:

              someResultHandler(event:ResultEvent):void
              {
              .....
              myList = event.result.list;
              ....
              }

              I couldn't tell from your last message whether you had already resolved the problem. If not, the above should help.

              Do remember that Flex treats dataProviders in a case-sensitive fashion. So, if it's <list> but youre referring to LIST, that is a big difference.

              • 4. Re: Simple dataProvider for dataGrid question
                nate1003 Level 1
                Thanks again for responding. I've tried that, but when I do all the values show up in the first row of the datagrid. Which looks like this:
                <item>value</item>
                <item>value2</item>
                <item>value3</item>

                Perhaps I'm making an incorrect assumption below:

                [Bindable]
                public var myList:XMLList;
                .........
                myList = event.result.list;
                .........
                <mx:DataGrid dataProvider="{myList}" width="100%">
                <mx:columns>
                <mx:DataGridColumn headerText="Names" dataField="item"/>
                </mx:columns>
                </mx:DataGrid>

                xml from server:
                <topnode>
                <list>
                <item>value</item>
                <item>value2</item>
                <item>value3</item>
                </list>
                </topnode>