14 Replies Latest reply on Dec 9, 2008 10:41 AM by kdennis4

    Two arrays to Populate Datagrid

    kdennis4 Level 1
      Hello All,

      This is what I have so far:

      //Create new variables and type it as an ArrayCollection
      public var firstAC:ArrayCollection;
      public var secondAC:ArrayCollection;

      private function initData():void {
      //Give the new ArrayCollection some values
      firstAC = new ArrayCollection(["action:"]);
      secondAC = new ArrayCollection(["myTest"]);

      <mx:DataGrid dataProvider="{firstAC},{secondAC}" width="676" height="403" textAlign="right" fontWeight="bold" fontSize="12">
      <mx:columns>
      <mx:DataGridColumn dataField="col_01" headerText="Data Fields" width="365"/>
      <mx:DataGridColumn dataField="col_02" headerText="Data"/>
      </mx:columns>
      </mx:DataGrid>

      Any help would be greatly appreciated!
        • 1. Re: Two arrays to Populate Datagrid
          kdennis4 Level 1
          Hello All,

          Well, I've got this thing partially working, but I still would appreciate any help. This is working:

          [Bindable] public var ac:ArrayCollection = new ArrayCollection([
          {columnList: "ACTION:", dataList: "myTest"}
          ]);

          <mx:DataGrid dataProvider="{ac}" width="676" height="403" textAlign="right" fontWeight="bold" fontSize="12">
          <mx:columns>
          <mx:DataGridColumn dataField="columnList" headerText="Data Fields" width="365"/>
          <mx:DataGridColumn dataField="dataList" headerText="Data"/>
          </mx:columns>
          </mx:DataGrid>

          What I need is for the columnList to be more than one, and the dataList to be more than one. What I am attempting to do is call a CFC and return the columnList as an array, and then the associated data as an array. Any feedback or clues as to whether this will work with my current code, and is the syntax the same within the new Arraycollection? Thanks in advance!
          • 2. Re: Two arrays to Populate Datagrid
            kdennis4 Level 1
            Hello All,

            Well I think I figured it out, so I thought I would share for future reference to anyone else that may run across this issue:

            What I've done is taken the list of column names and will only return the query of the data from a CFC call. Something like this I think:

            Bindable] public var ac:ArrayCollection = new ArrayCollection([
            {columnList: "ACTION:", dataList: "myTest[0]"},
            {columnList: "REQUESTED:", dataList: "myTest[1]"},
            {columnList: "CODE:", dataList: "myTest[2]"},
            {columnList: "CATEGORY:", dataList: "myTest[3]"}
            ]);

            If anyone has a different approach that would be great, but I think this will work!
            • 3. Re: Two arrays to Populate Datagrid
              kdennis4 Level 1
              Hello All,

              Well, I'm working through one last issue. The array is not being populated correctly. Does anyone know how to properly code for the array?:

              columnList: "ACTION:", dataList: "myTest[0]"},
              {columnList: "REQUESTED:", dataList: "myTest[1]"},

              It literally displays "myTest[0]", etc... in the dataGrid instead of the value. Any suggestions? Thanks!
              • 4. Re: Two arrays to Populate Datagrid
                jfb00 Level 3
                Hi,
                I think the best approach is to create a third array base on the two that you have and use that for the grid.
                I hope this help.
                Rgds

                JFB
                • 5. Re: Two arrays to Populate Datagrid
                  kdennis4 Level 1
                  Hi JFB,

                  I've got this code now, but it's returning [ object Object ]:

                  [Bindable]
                  public var firstAC:String = pdqrCollection[0]; (where pdqrCollection is a list of values)

                  then:

                  [Bindable] public var ac:ArrayCollection = new ArrayCollection([
                  {columnList: "ACTION:", dataList: firstAC}, etc... firstAC is the object return, and I've tried firstAC[0]

                  I think I can get it if I can create the right syntax. Do you know what I'm doing wrong? Thanks for your input. I really appreciate it!
                  • 6. Re: Two arrays to Populate Datagrid
                    kdennis4 Level 1
                    Hello All,

                    I've tried this, and I'm still getting [ object Object ]:

                    [Bindable] public var firstAC:String = pdqrCollection.getItemAt(0).toString();

                    [Bindable] public var ac:ArrayCollection = new ArrayCollection([
                    {columnList: "ACTION:", dataList: firstAC}, etc...

                    Any suggestions? Thanks in advance!
                    • 7. Re: Two arrays to Populate Datagrid
                      Level 7

                      "kdennis4" <webforumsuser@macromedia.com> wrote in message
                      news:ghc3g5$q4p$1@forums.macromedia.com...
                      > Hello All,
                      >
                      > Well I think I figured it out, so I thought I would share for future
                      > reference
                      > to anyone else that may run across this issue:
                      >
                      > What I've done is taken the list of column names and will only return the
                      > query of the data from a CFC call. Something like this I think:
                      >
                      > Bindable] public var ac:ArrayCollection = new ArrayCollection([
                      > {columnList: "ACTION:", dataList: "myTest[0]"},
                      > {columnList: "REQUESTED:", dataList: "myTest[1]"},
                      > {columnList: "CODE:", dataList: "myTest[2]"},
                      > {columnList: "CATEGORY:", dataList: "myTest[3]"}
                      > ]);
                      >
                      > If anyone has a different approach that would be great, but I think this
                      > will
                      > work!

                      What you need is:

                      [{ACTION:"something", REQUESTED: "something else", CODE: "some other thing",
                      CATEGORY:"data for category"},
                      {ACTION:"something record 2", REQUESTED: "something else record 2", CODE:
                      "some other thing record 2", CATEGORY:"data for category in record 2"}]

                      Then you can just set up the datagrid to read each field. Though I
                      personally wouldn't recommend having object properties in all caps.

                      HTH;

                      Amy


                      • 8. Two arrays to Populate Datagrid
                        kdennis4 Level 1
                        Hello All,

                        I'm still getting a return of [object Object] ??? Here is my code:

                        [Bindable] public var firstAC:ArrayCollection = new ArrayCollection ([
                        {pqdrAC:'Here,There'}
                        ]);

                        [Bindable] public var ac:ArrayCollection = new ArrayCollection([
                        {columnList: "ACTION:", dataList: firstAC[0]},
                        {columnList: "REQUESTED:", dataList: firstAC}, etc, etc...

                        If I place the second dataList value at "firstAC[1]" without the "" then the page doesn't even display??? I think I'm just missing the proper syntax. Any clues? Thanks in advance!
                        • 9. Re: Two arrays to Populate Datagrid
                          Level 7

                          "kdennis4" <webforumsuser@macromedia.com> wrote in message
                          news:ghlvoc$d75$1@forums.macromedia.com...
                          > Hello All,
                          >
                          > I'm still getting a return of [object Object] ??? Here is my code:
                          >
                          > [Bindable] public var firstAC:ArrayCollection = new ArrayCollection ([
                          > {pqdrAC:'Here,There'}
                          > ]);
                          >
                          > [Bindable] public var ac:ArrayCollection = new ArrayCollection([
                          > {columnList: "ACTION_DISPOSITION:", dataList: firstAC[0]},
                          > {columnList: "ACTION_REQUESTED:", dataList: firstAC}, etc, etc...
                          >
                          > If I place the second dataList value at "firstAC[1]" without the "" then
                          > the
                          > page doesn't even display??? I think I'm just missing the proper syntax.
                          > Any
                          > clues? Thanks in advance!

                          That doesn't look very much like you followed my advice--you're still trying
                          to fight the way DataGrid is designed to work instead of working _with_ it.
                          You may find that an OLAP datagrid will be more to your needs.


                          • 10. Re: Two arrays to Populate Datagrid
                            kdennis4 Level 1
                            Thanks Amy, but I didn't see anything on the OLAP Datagrid that explains what I'm trying to do. What I wrote before after calling a RemoteObject CFC:

                            What I need is for the columnList to return from a query, and the dataList to return the associated data as an array.

                            So if you disregard what I've hard coded, I am trying to figure out the correct syntax to output the array(s). Something like this:

                            [Bindable] public var ac:ArrayCollection = new ArrayCollection([
                            {columnList: firstCFCQueryCall[0], dataList: dataReturned[0]},
                            {columnList: firstCFCQueryCall[1], dataList: dataReturned[1]}, etc, etc...

                            Just from hard coding an array, I'm getting [object Object] so it's got to be something in my syntax. I will be replacing the hard coded array with a return from a CFC query. If you know of any good examples, I sure would appreciate it! :0)
                            • 11. Re: Two arrays to Populate Datagrid
                              ntsiii Level 3
                              "[object Object]" means you are trying to display a complex object in control that requires a string.

                              I am still not sure what you are trying to do. Please explain again, in words, rather than in code.

                              Tracy
                              • 12. Re: Two arrays to Populate Datagrid
                                kdennis4 Level 1
                                Hello Tracy,

                                I have created two separate queries within a CFC. One to return the Column List, and one to return the data from those Columns. I will call and return these with the <mx:RemoteObject> tag. Within a function I will receive the Column List as an array. Within another function I will receive the data as an array. Next I need to group these two and set the values so that the first Column name and the first piece of data are in line with each other. I hard coded an array to try and figure out the syntax for those values to display. I think I should be working with 3 different arrays, with the third being the final like:

                                colulnmList: columnName[0] dataList:data[0]
                                colulnmList:columnName[1] dataList:data[1]

                                then for those to display:

                                <mx:DataGridColumn dataField="columnList" headerText="Data Fields" width="365"/>
                                <mx:DataGridColumn dataField="dataList" headerText="Data"/>

                                The first and second array I hard coded works fine, but I need to use the CFC to return those values instead. I hope this makes better sense, and thank you in advance for your help! :0)
                                • 13. Re: Two arrays to Populate Datagrid
                                  ntsiii Level 3
                                  Ok, I would not do it that way. I would use the columns data to dynamically build the DataGrid. here is an example. It uses xml data to define the columns rather than a separate data set but the theory is the same.
                                  http://www.cflex.net/showFileDetails.cfm?ObjectID=552

                                  Now, to proceed on the course you have started, you could loop over your data array, then inside that "row" loop, loop over the colum array and build your item objects there.

                                  That should work. But building the DataGrid dynamically will allow you much more control over the DG, such as headers, widths, etc.

                                  Tracy
                                  • 14. Re: Two arrays to Populate Datagrid
                                    kdennis4 Level 1
                                    Hi Tracy,

                                    Thanks so much! :0)