6 Replies Latest reply on May 31, 2007 1:51 PM by fuzzarooO

    Datagrid: Preparing my DataProvider Correctly

    fuzzarooO Level 1
      Hi guys, I'm trying to get a grid that shows something like

      columns --> Apple Cherries Oranges
      Data --> 5 4 24

      the way my arrayCollection is set up is to support dynamic data and columns.

      myArray[0].fruit = apple;
      myArray[0].remaining = 5;
      etc.

      my column function is this and is executed on creationCompletion:

      [Bindable] public var chartProvider:ArrayCollection = new ArrayCollection();

      private function createColumns() : void {
      var dgCols : Array = new Array();

      for(var i:Number=0; i<chartProvider.length;i++){
      var dgc:DataGridColumn = new DataGridColumn();
      dgc.headerText = myArray .fruit;
      dgc.dataField = "remaining";
      dgCols.push(dgc);
      }
      lineGrid.columns = dgCols;
      };

      for some reason, my grid looks like this:

      Apple Cherries Oranges
      5 5 5
      4 4 4
      24 24 24

      any ideas? Thanks!
        • 1. Re: Datagrid: Preparing my DataProvider Correctly
          peterent Level 2
          GIven your data, the dataProvider for the DataGrid should look like this:

          myArray[0] = { apple:5, cherries:4, oranges:24 };
          myArray[1] = { apple:8, cherries:3, oranges:18};
          etc.
          • 2. Datagrid: Preparing my DataProvider Correctly
            fuzzarooO Level 1
            pete, I see i messed up explainign my example with apples, cherries, and oranges.

            let me give you a better example:

            [Bindable] public var myb:ArrayCollection = new ArrayCollection();

            public function doit():void{
            var mya:Array= new Array();
            var tempo:Object = new Object();
            tempo["09/01/02"] = "40";
            tempo["02/02/02"] = "20";
            tempo["04/04/04"] = "50";
            mya.push(tempo);
            myb = new ArrayCollection(mya);
            }

            ----

            <mx:DataGrid id="test" x="10" y="246" dataProvider = "{myb}" creationComplete = "{doit()}"></mx:DataGrid>

            now my columns aren't correct at all? I'm getting:
            02/02/02 04/04/04 09/01/02
            50 20 40

            i don't want my columns to sort.. how can i stop that. so that I get them like:

            09/01/02 02/02/02 04/04/04

            thanks
            • 3. Re: Datagrid: Preparing my DataProvider Correctly
              peterent Level 2
              You are getting what you are supposed to get.

              tempo["09/01/02"] = 40; 09/01/02 is the dataField for the DataGridColumn. The 40 is the value for that field on that record.

              What you want is more like:

              { col1:"09/01/02", col2:"02/02/02", col3:"04/04/04"} which represents one record. You need to determine what your data field names will be.
              • 4. Re: Datagrid: Preparing my DataProvider Correctly
                fuzzarooO Level 1
                but then my column headers are no longer dates, but are col1, col2, and col3. I want my column headers to be dates.

                sorry for the confusion, but i do appreciate your patience.
                • 5. Re: Datagrid: Preparing my DataProvider Correctly
                  peterent Level 2
                  I guess I really don't understand then. You already have column headers that are dates. Can you show a full example, like this:

                  09/01/06.......................10/01/06......................11/01/06
                  ----------------------------------------------------------------------
                  40...................................... 50..................................70
                  90......................................30.................................. 40

                  Is this what you want?
                  • 6. Re: Datagrid: Preparing my DataProvider Correctly
                    fuzzarooO Level 1
                    yeah, but not in that order -- the problem is my colum headers are being sorted.

                    u'll notice thats the difference in my example.

                    var tempo:Object = new Object();
                    tempo["09/01/02"] = "40";
                    tempo["02/02/02"] = "20";
                    tempo["04/04/04"] = "50";

                    gives me :
                    02/02/02 04/04/04 09/01/02
                    20 50 40

                    but what I want is it to not be sorted. I should be getting :
                    09/01/02 02/02/02 04/04/04
                    40 20 50