2 Replies Latest reply on Oct 29, 2009 10:37 AM by Mike6679

    XMLList For Datagrid

    Mike6679 Level 1

      Hi,

       

      I'm using EX4 to search XML and then trying to populate my datagrid. Easy enough. Howerver. I can't figure out hhow to get the "name" node to show up in my results. Its the "name" node I'm searching on and in the results, its the root node. How can I get that node into my "Category" column?? Do I have to manually insert it into each row....but then how do I do that because in a datagrid you have to populate an entire row at once, you just can't populate one cell right?

       

      //// XML ////////

       

      <myxml>

      <category name="TOXICOLOGY">

      <entry>
      <keywords>  Digoxin  </keywords>
      <code> 972.1 </code>
      </entry>

      <entry>
      <keywords>  Immunosuppressive agents  </keywords>
      <code> 963.1 </code>
      </entry>

      <entry>
      <keywords>  After care for Immunosuppressive agents  </keywords>
      <code>  V58.69  </code>
      </entry>
      </category>

       

      </myxml>

       

       

       

       

      /////// Datagrid ///////


      <mx:DataGrid x="0" y="88" width="400" height="368"  id="datagrid_codes">
              <mx:columns>
                  <mx:DataGridColumn headerText="Keyword" dataField="keywords"/>
                  <mx:DataGridColumn headerText="Category" dataField="name"/>
                  <mx:DataGridColumn headerText="Code" dataField="code"/>
              </mx:columns>
          </mx:DataGrid>

       

       

      /////  code to search  ///////////

       

      m_xml_list = m_theFullXML.category.(@name == string  );

      m_datagridCodes.dataProvider = m_xml_list.children();

        • 1. Re: XMLList For Datagrid
          paul.williams Level 4

          Perhaps you could set-up a labelFunction on your Category column and return the currently selected name from that?

           

          http://livedocs.adobe.com/flex/3/langref/mx/controls/dataGridClasses/DataGridColumn.html#l abelFunction

          • 2. Re: XMLList For Datagrid
            Mike6679 Level 1

            Thanks Paul. I didn't try your suggestion because I found a workaround by using an array

             

             

            public function search(string:String,category:Boolean):void
                    {
                       
                        if(category)
                        {
                            m_xml_list = m_theFullXML.category.(@name == string  );
                          
                            m_datagridCodes.dataProvider = m_xml_list.children();
                           
                            //we know the category so lets populate it as well..
                   
                            //poulate array with new row item data
                            var dp:Array = new Array();
                            for (var idx:int =0 ;idx < IList(m_datagridCodes.dataProvider).length ; ++idx)
                            {
                                var ObjOrig:Object = IList(m_datagridCodes.dataProvider).getItemAt(idx);
                             
                                var ItemSourceObjFinal:Object = {keywords: ObjOrig.keywords  ,
                                                                 name: string ,
                                                                 code: ObjOrig.code };
                                dp.push(ItemSourceObjFinal);
                            }
                            m_datagridCodes.dataProvider = dp;
                   
                        }