8 Replies Latest reply on Jun 27, 2009 1:49 AM by karthik flex

    how to pass particular data to particular column in datagrid?

    karthik flex Level 1

      hi

       

       

      i have an xml

       

      <timeIntervals>
      <timekey>
      <physicians name="karthik">
      <schedule activity="FOLLOW-UP"/>
      </physicians>
      <physicians name="Suresh">
      <schedule activity="ANNUAL PHYSICAL" />
      </physicians>
      </timekey>
      </timeIntervals>

       

      my req
      there are two "xphysicians " tag
      first xphysicians tag should be in one column and second xphysicians physician tag is in next column i.e
      FOLLOW-UP should be in one column and ANNUAL PHYSICAL should be in second column
      but

       

      when it is displaying, it is displaying all in  one column because xphysicians tag are same
      when i change two
      xphysicians to xphysicians1 and xphysicians2 it is displaying according to my req

      how to traverse through xml and hold it and display

       

      but my client is not changing the xml to xphysicians1 and xphysicians2

      any idea

       

      karthik.k

        • 1. Re: how to pass particular data to particular column in datagrid?
          DaveFastFingers Level 1

          I think this is what you're looking for:

           

          The MXML below produces the output:

               karthik     FOLLOW-UP

               Suresh     ANNUAL PHYSICAL

           

          I'm pretty new at this too, so it took some fussing around to get this to work (I just finished working with DataGrids today). I think what is important to realize here is that the DataGrid is taking an XMLList object, so it's converting the XML to an XMLList. Essentially that means that it is just reading the first set of children under the root tag and displaying those.

           

          What you had defined before was 1 row, namely the row <timekey> (that is the first set nodes under the root <timeIntervals>). If you had multiple <timekey> nodes then you would have gotten the physicians under each <timekey> on a separate line.

           

          By changing the data provider to point to "myXML.timekey.physicians", this returns an XMLList of <physicians ...> nodes, thus you end up with 2 separate <physicians> nodes in the XMLList rather than just the one <timekey> node.

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:XML id="myXML">
                  <timeIntervals>
                      <timekey>
                          <physicians name="karthik">
                              <schedule activity="FOLLOW-UP"/>
                          </physicians>
                          <physicians name="Suresh">
                              <schedule activity="ANNUAL PHYSICAL" />
                          </physicians>
                      </timekey>
                  </timeIntervals>
              </mx:XML>
             
                  <mx:DataGrid id="dg" width="100%" height="100%" dataProvider="{myXML.timekey.physicians}">
                          <mx:columns>
                              <mx:DataGridColumn dataField="@name" headerText="Physicians Name"  />
                              <mx:DataGridColumn dataField="schedule.@activity" headerText="Activity" />
                          </mx:columns>
                  </mx:DataGrid>
          </mx:Application>

          • 2. Re: how to pass particular data to particular column in datagrid?
            karthik flex Level 1

            hi Dave

             

            Thank you for spending your precious time

             

            the output which i was looking for is

             

            karthik               Suresh   

             

            FOLLOW-UP   ANNUAL PHYSICAL

             

             

            Karthik and suresh is in header text and FOLLOW-UP and ANNUAL PHYSICAL will be right below the header text resp

             

            because i am creating dynamic datagrid where the xml looks so similar and i need in the above format

             

            Dave let me know whether we can do with the existing xml or we need to change the format

             

             

            karthik.k

            • 3. Re: how to pass particular data to particular column in datagrid?
              DaveFastFingers Level 1

              That seems like a very uncommon use of a datagrid, not only technically, but for another reason that I'll explain next. First technically, the data grid is designed to list similar data in each column, since <physician> and <scedule> are different data fields it's not straight forward to define lthe logic that you want per column, for example, where would the 3rd row of data come from? It's not obvious and would require defining the logic somewhere.  Thus from a technical standpoint it makes sense that you need to re-organize the data if you really want it that way. The data for a column must all be similar, such as physicians.@name. You can re-parse the XML into a new format for the data grid, the algorithm used to re-parse it would contain the logic that defines what is in row #1, row #2, row #3, etc.

               

              Second, it seems like what you want to have happen is for the # of columns to grow as the # of physicians grows. If this is the case things are going to get pretty messy on the screen pretty quickly. Not to mention the fact that a data grid isn't designed for this kind of format. If that's what you want (which I wouldn't recommend) then you'll need a fair amount of code to re-size the data grid each time the data source changes, and you will also need to re-parse the data source so that the datagrid can read it.

               

              If you really do need data listed in columns then I would recommend re-thinking the format of the data. I'm not 100% clear how you want to extend the presentation of the data (e.g. more physicians, more columns, or more rows of related data to a fixed # of physicians) but I would suggest considering how you want the data to expand. Or post here how you want to see a larger set of data and I and others can maybe make some more suggestions.

               

              David

              • 4. Re: how to pass particular data to particular column in datagrid?
                karthik flex Level 1

                Fine i got it , you said me to redefine

                 

                how can the xml be , if i need in that format


                for example, i changed the xml to

                 


                <timeIntervals>
                <timekey>
                <physicians1 name="karthik">
                <schedule activity="FOLLOW-UP"/>
                </physicians1>
                <physicians2 name="Suresh">
                <schedule activity="ANNUAL PHYSICAL" />
                </physicians2>
                </timekey>
                </timeIntervals>

                 


                i got the required output

                 

                i placed "name" as headertext and in the datafield as "activity" as datafield and so on

                 


                if my xml is wrong please give me your suggession

                • 5. Re: how to pass particular data to particular column in datagrid?
                  DaveFastFingers Level 1

                  The data for a given column has to be the same format, for example:

                   

                  <timeIntervals>
                       <timekey>
                            <column 1st="karthik" 2nd="Suresh"/>

                            <column 1st="FOLLOW-UP"2nd="ANNUAL PHYSICAL"/>

                       </timekey>

                  </timeIntervals>

                   

                  There are of course other XML formats that will work, but this shows an example. For each column you need to be able to refer to one type of XML data, for example: "timeIntervals.timekey.column.@1st" for the first column, and "timeIntervals.timekey.column.@2nd" for the 2nd column, so that the datagrid can find all instances of that data for the particular column.

                   

                  Does that make sense? Let me know if it doesn't, it's a bit tricky to put down in words.

                   

                  I still think it would be a good exercise to explain the logic that you want with your original example, I think it will help point out the logical problem with laying out data this way. Specifically, in your original example, what data would be at row 3 in an expanded data set? Are there any cases where a new column would need to be added based on the data set?

                   

                  Answering those questions will make recommending one thing or another easier too because I'm still not 100% clear on what you are expecting as the dataset grows (I assume your real world use case would not have only 2 rows and 2 columns of data otherwise you would probably just use a text field of some sort).

                   

                  David

                  • 6. Re: how to pass particular data to particular column in datagrid?
                    karthik flex Level 1

                    hi dave

                     

                    the xml you gave i just modified a few (I think you can understand)

                     

                    <timeIntervals>

                    <xphysicians>

                         <timekey>
                              <column 1st="karthik" 2nd="FOLLOW-UP"/>
                              <column 1st="Suresh" 2nd="ANNUAL PHYSICAL"/>

                         </timekey>

                         <timekey>
                               <column 1st="babu" 2nd="FOLLOW-UP"/>
                               <column 1st="appu" 2nd="ANNUAL PHYSICAL"/>

                         </timekey>

                    </xphysicians>
                    </timeIntervals>

                     

                    My exact requirement is

                     

                    Column 1 (Header Text)                 Column 2 (Header Text)


                    karthik   FOLLOW-UP                    babu   FOLLOW-UP

                    Suresh  ANNUAL PHYSICAL        appu  ANNUAL PHYSICAL 

                     

                    the two data i.e karthik   FOLLOW-UP

                                             Suresh  ANNUAL PHYSICAL   should come inside one row

                     

                    you can see i added two node in xml     <xphysicians> which is the 1st root node

                    Inside that two <timekey>

                     

                    There might be more <xphysicians> added at the end

                     

                    this is what my client needs

                     

                    My point of view is that when i change the two timekey to (timekey1 and timekey2) i am getting the required output but my client is not happy with that format

                     

                    Should i need to write any itemrenderer(If required)

                     

                     

                    I think you can understand

                     

                    This is my requirement

                     

                    Karthik.k

                    • 7. Re: how to pass particular data to particular column in datagrid?
                      DaveFastFingers Level 1

                      Hmm, I did get a bit lost here.

                       

                      So in this example is Karthik the first name, and Suresh the last name?

                       

                      And you are looking for column 1, row 1 to read something like: "karthik Suresh FOLLOW-UP ANNUAL PHYSICAL"

                      And in column 2, row 1 you want it to read (I'm taking out line breaks for simplicity): "babu appu FOLLOW-UP ANNUAL PHYSICAL"

                      Then I assume row 2 would have another set of data from another <xphysicians> tag?

                       

                      If so then I'm not quite following the logic you want to apply to take data from the XML structure. If my above assumptions are correct then the XML is in a rather bizzar format. But I'm probably just not understanding properly.

                       

                      Let me know if you haven't worked it all out by now and I'll do my best to understand and help.

                       

                      Dave

                      • 8. Re: how to pass particular data to particular column in datagrid?
                        karthik flex Level 1

                        hi dave

                         

                        So in this example is Karthik the first name, and Suresh the last name?

                         

                        no these two names are some clients entering in to a shop

                         

                        FOLLOW-UP , ANNUAL PHYSICAL


                        are nothing but some reports so

                         

                        Karthik should match with  FOLLOW-UP and

                        Suresh should match with ANNUAL PHYSICAL

                         

                         

                        <timeIntervals>

                        <xphysicians>

                             <timekey>
                                  <column 1st="karthik" 2nd="FOLLOW-UP"/>
                                  <column 1st="Suresh" 2nd="ANNUAL PHYSICAL"/>

                             </timekey>

                             <timekey>
                                   <column 1st="babu" 2nd="FOLLOW-UP"/>
                                   <column 1st="appu" 2nd="ANNUAL PHYSICAL"/>

                             </timekey>

                        </xphysicians>

                        <xphysicians>

                             <timekey>
                                  <column 1st="charles" 2nd="FOLLOW-UP"/>
                                  <column 1st="Guru" 2nd="ANNUAL PHYSICAL"/>

                             </timekey>

                             <timekey>
                                   <column 1st="Mohan" 2nd="FOLLOW-UP"/>
                                   <column 1st="kumar" 2nd="ANNUAL PHYSICAL"/>

                             </timekey>

                        </xphysicians>


                        </timeIntervals>

                         

                        My exact requirement is

                         

                        Column 1 (Header Text)                 Column 2 (Header Text)


                        karthik   FOLLOW-UP                    babu   FOLLOW-UP

                        Suresh  ANNUAL PHYSICAL        appu  ANNUAL PHYSICAL 

                         

                         

                        Then I assume row 2 would have another set of data from another <xphysicians> tag?

                        yes you are right

                         

                        it should not display like "karthik Suresh FOLLOW-UP ANNUAL PHYSICAL"


                        atleast like " karthik FOLLOW-UP Suresh ANNUAL PHYSICAL"

                         

                        karthik.k