8 Replies Latest reply on Jun 11, 2008 4:43 PM by Kukiwon

    Read data from Datagrid

    Kukiwon
      Hi all,
      I populated a Datagrid(three columns), users can drop and drag products from this datagrid to another one to delete their product. At the bottom of my first datagrid i have a label that says how many products are ordered. This is just the sum of the last Column in my datagrid, but i can't seem to find out how to read the data from just the last column to sum these values up and update my label.

      Thanks in advance,

      Jordy
        • 1. Re: Read data from Datagrid
          ntsiii Level 3
          IMPORTANT: You *never* read data from a DataGrid. You always read the dataProvider.

          Just loop over the dataProvider and sum the values in the appropriate property. How you do this depends on the dataType of the dataProvider.

          Tracy
          • 2. Re: Read data from Datagrid
            Kukiwon Level 1
            the dataType of my dataProvider is just text, the dataProvider itself is just an arraycollection. I have no idea how to "loop over the dataProvider".

            Thanks,

            Jordy
            • 3. Re: Read data from Datagrid
              semony_TT
              when u declare dataProvider in mxml like this it creates a binding.

              dataProvider={yourArray}

              and when ever you perfrom a drag and drop the same changes will be made to your "yourArray"

              so what u have to do is, after drag and drop is complete

              yourArray[ yourArray.length-1 ] will be the new product u just entered.


              if u add Event.Change to your Array u'll see what I mean. I think this is an simpler approach and is straight forward. Altho there is another way you can do it by overiding existing functions..
              • 4. Read data from Datagrid
                Kukiwon Level 1
                I'll quickly try to tell my whole problem:
                The users have to fill in a form (13 products).
                After they've done this, thet click next and the following function is called: setDatagrid();
                When users drag a product from this datagrid to another one (to delete one of their chosen products), the lenght of this datagrid is indeed myArray.length-1. At the bottom there's a label, total amount of products, which has to substract the value from the last column in my grid (amount) from the dragged out row. Now a function has to recalculate the remaining values of the last column in my grid and update the label. I understand I have to do this with an event, but i just don't know how to "read" the remaining values in the last column of my dataGrid.
                I'm new to Flex, i appreciate your time!

                Thanks,

                Jordy

                • 5. Re: Read data from Datagrid
                  Kukiwon Level 1
                  Hi,
                  I found out how to "loop" through my arrayCollection with the function updateAantal();
                  The problem is that this function doesn't do a thing!
                  my label doesn't get updated...

                  Here is my code:

                  • 6. Re: Read data from Datagrid
                    ntsiii Level 3
                    Why not?

                    Is the function being called? Is iQty getting updated? Does it have the correct value after the loop ends? Does aantal.text exist? Does it have a value before you start the loop? Does it have a value after you assign iQty?

                    Debug this function.

                    Tracy
                    • 7. Re: Read data from Datagrid
                      Kukiwon Level 1
                      I'm calling this function from a button.
                      aantal.text doesn't change at all when clicking my Update. I know there's nothing wrong with my button or label. when i just use this:
                      private function updateAantal():void{
                      var iQty:int = 0;

                      aantal.text = "" + iQty;
                      }
                      Then my function updates the label.
                      The problem has to be in one of these lines:

                      for (var i:int=0;i<overzichtArray.length;i++) {
                      iQty += overzichtArray.getItemAt(i).Aantal;
                      }

                      When I just create an empty for loop (delete the second line), the function does nothing, when I only use the second line and replace the i with 0, the function also does nothing...

                      Thanks,

                      Jordy
                      • 8. Re: Read data from Datagrid
                        Kukiwon Level 1
                        I've foun a solution to my problem.
                        before, my datagrid looked this way:
                        <mx:DataGrid x="10" y="10" width="468" height="378" dragMoveEnabled="true" dragEnabled="true" id="overzicht_grid" borderColor="#A3A3A3" themeColor="#616161" dropEnabled="true" enterFrame="updateAantal();">

                        now I have set it to this:
                        <mx:DataGrid x="10" y="10" width="468" height="378" dragMoveEnabled="true" dragEnabled="true" id="overzicht_grid" borderColor="#A3A3A3" themeColor="#616161" dropEnabled="true" dataProvider="{overzichtArray}" enterFrame="updateAantal();">
                        I added a default Dataprovider wich is empty at first.
                        now my code works.

                        Thanks for the help!

                        Jordy