2 Replies Latest reply on Dec 17, 2009 10:46 PM by vksvicky

    DataGrid + Dynamic Display on Selection

    vksvicky

      Back again with another Flex question.

      I have an XML structure like...

       

      <Student>
       
      <Name>X</Name>
       
      <Age>14</Age>
      </Student>

      <Student>
       
      <Name>Y</Name>
       
      <Age>16</Age>
       
      <Address>
         
      <HNumber>1</HNumber>
         
      <HName>Something</HName>
         
      <HPin>33607</HPin>
       
      </Address>
      </Student>

      Now I got his displaying on my grid by saying dataProvider=XMLListCollection...

       

      What I want to do is on selection of a row, check if it has "Address" tag, if it has display the other grid, else hide the grid.

      Any help!!

        • 1. Re: DataGrid + Dynamic Display on Selection
          RK...

          Can you try this,

           

          private var xmlDP: XML = <Students>
               <Student>
                 <Name>X</Name>
                 <Age>14</Age>
               </Student>
               <Student>
                 <Name>Y</Name>
                 <Age>16</Age>
                 <Address>
                    <HNumber>1</HNumber>
                    <HName>Something</HName>
                    <HPin>33607</HPin>
                 </Address>
               </Student>
          </Students>;
          
          private function onChange(event: ListEvent): void {
               dg1.visible = (new XMLList(dg.selectedItem.Address).length() > 0);
          }
          

           

          <mx:DataGrid id="dg" dataProvider="{xmlDP.Student}" change="onChange(event)">
               <mx:columns>
                    <mx:DataGridColumn headerText="Name" dataField="Name" />
                    <mx:DataGridColumn headerText="Age" dataField="Age" />
               </mx:columns>
          </mx:DataGrid>
          <mx:DataGrid id="dg1" dataProvider="{dg.selectedItem.Address}" visible="false">
               <mx:columns>
                    <mx:DataGridColumn headerText="HNumber" dataField="HNumber" />
                    <mx:DataGridColumn headerText="HName" dataField="HName" />
                    <mx:DataGridColumn headerText="HPin" dataField="HPin" />
               </mx:columns>
          </mx:DataGrid>
          

          1 person found this helpful
          • 2. Re: DataGrid + Dynamic Display on Selection
            vksvicky Level 1

            RK, it works pretty well, thought I had to do some tweaking.

             

            Thanks!!