6 Replies Latest reply on Jun 14, 2007 8:32 PM by Newsgroup_User

    auto datagrid

    Level 7
      public function addPriceRow():void{
      var tempPrice:Object= new Object();
      tempPrice = price_RO.init();

      this.price_dg.dataProvider = tempPrice;
      this.price_dg.editable = true;
      this.price_dg.setFocus();
      }

      private function renderPrice():String{
      return String( ); --> here should be the calculations
      }

      <mx:DataGrid id="price_dg" x="10" y="28" width="590" height="84">
      <mx:columns>
      <mx:DataGridColumn headerText="Quantity" dataField="qty"/>
      <mx:DataGridColumn headerText="Piece" dataField="piece"/>
      <mx:DataGridColumn headerText="Product" dataField="product"/>
      <mx:DataGridColumn headerText="fee" dataField="fee"/>
      <mx:DataGridColumn headerText="Total" dataField="total"
      labelFunction="renderPrice" editable="false"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:Button x="385" y="0" label="Add Row" click="addPriceRow()"/>
      <mx:Button x="494" y="0" label="Delete Row"/>

      Hi All,
      I'm using coldfusion and flex2 in my app.
      Let's said that I'm creating a datagrid like a shopping card with Add and
      delete buttons.
      When I add a item, I create a new row and initializing my object from the
      cfc with defaul values but they dont show in the datagrid.
      Also I have a total field, I'm using labelFunction but how can I get the
      value of the other columns to calculate the total ((qyt * piece) + fee))
      I'm new in flex.. please help.
      Any links?
      Tks

      JFB


        • 1. Re: auto datagrid
          ntsiii Level 3
          Hmm, does this work at all? You are setting the entire dataProvider to the newly initialized new item object. That should result in a single row, assuming price_RO.init(); returns a valid dataProvider collection.

          You want instead to use the dataProvider API to add the new item.

          You are not showing a dataProvider assignment in the dataGrid. What is the dataProvider?

          Regarding labelFunction(), the correct method signature is:
          labelFunction(item:Object, column:DataGridColumn):String

          "item" is a reference to the *entire* item object, so contains the values for all the properties in the curent item.

          "column" is a refernce to the DataGridColumn, so you can use that to determine what to return. This lets you have a single labelFunction for multiple columns.

          Tracy
          • 2. Re: auto datagrid
            Level 7
            Thank for you reply Tracy,
            You are correct, I dont have dataprovider... I need to add a row by row and
            then at save form time I will pass all to a table.
            price_RO.init(); is just setting one row... so how do I add one row to
            datagrid? and set focus to the first left column of that row?
            How can I get the entire datagrid rows later to save in my table?
            I have the method create.. but this create one row... I don't want to create
            one row o delete row on the database everytime, I want to do it at save
            time.
            I'm going to try the labelFunction/
            Rgds

            JFB

            "ntsiii" <tspratt@lariatinc.com> wrote in message
            news:f4pmkr$4h4$1@forums.macromedia.com...
            > Hmm, does this work at all? You are setting the entire dataProvider to
            > the
            > newly initialized new item object. That should result in a single row,
            > assuming price_RO.init(); returns a valid dataProvider collection.
            >
            > You want instead to use the dataProvider API to add the new item.
            >
            > You are not showing a dataProvider assignment in the dataGrid. What is
            > the
            > dataProvider?
            >
            > Regarding labelFunction(), the correct method signature is:
            > labelFunction(item:Object, column:DataGridColumn):String
            >
            > "item" is a reference to the *entire* item object, so contains the values
            > for
            > all the properties in the curent item.
            >
            > "column" is a refernce to the DataGridColumn, so you can use that to
            > determine
            > what to return. This lets you have a single labelFunction for multiple
            > columns.
            >
            > Tracy
            >


            • 3. Re: auto datagrid
              Level 7
              hi Tracy,
              As you see I'm trying to use datagrid for input data.
              I can't pass the initial values from my init method in the cfc, I try struct
              and still not working
              Do you know why?
              Here is the code...
              <cfscript>
              //Initialize the CFC with the default properties values.
              variables.priceid = 0;
              variables.estimateid = 0;
              variables.qty = 0;
              variables.piece = 0;
              variables.productid= 0;
              variables.fee= 0;
              variables.total = 0;
              </cfscript>
              <cffunction name="init" output="false" returntype="any">
              <cfset request.tempStruc = StructNew()>
              <cfloop collection="#variables#" item="i">
              <cfset request.tempStruc[#i#] = variables[#i#]>
              </cfloop>
              <cfreturn request.tempStruc>
              </cffunction>

              The Error is: Type Coercion failed: cannot convert
              mx.utils::ObjectProxy@1c90e7c1 to mx.collections.ArrayCollection
              I need to pass these before I can play with the items.
              Tks

              JFB



              "ntsiii" <tspratt@lariatinc.com> wrote in message
              news:f4pmkr$4h4$1@forums.macromedia.com...
              > Hmm, does this work at all? You are setting the entire dataProvider to
              > the
              > newly initialized new item object. That should result in a single row,
              > assuming price_RO.init(); returns a valid dataProvider collection.
              >
              > You want instead to use the dataProvider API to add the new item.
              >
              > You are not showing a dataProvider assignment in the dataGrid. What is
              > the
              > dataProvider?
              >
              > Regarding labelFunction(), the correct method signature is:
              > labelFunction(item:Object, column:DataGridColumn):String
              >
              > "item" is a reference to the *entire* item object, so contains the values
              > for
              > all the properties in the curent item.
              >
              > "column" is a refernce to the DataGridColumn, so you can use that to
              > determine
              > what to return. This lets you have a single labelFunction for multiple
              > columns.
              >
              > Tracy
              >


              • 4. Re: auto datagrid
                ntsiii Level 3
                Sorry, i don't know CF.

                But adding a row to a datagrid is not hard, have you got that working?

                Tracy
                • 5. Re: auto datagrid
                  ntsiii Level 3
                  Hmm, start by creating an empty dataProvider variable and binding the DG to that.

                  then use the dataProvider API to add items.

                  Tracy
                  • 6. Re: auto datagrid
                    Level 7
                    Yes, I got it in that way creating an empty arraycollection and passing this
                    to the dataprovider.
                    Looks like it's hard to pass an struct or array from cfc to flex page... I
                    will keep searching for it.
                    Now I have a question bellow about putting a combo inside this datagrid with
                    different dataprovider source.
                    Tks Tracy

                    JFB


                    "ntsiii" <tspratt@lariatinc.com> wrote in message
                    news:f4stsg$65q$1@forums.macromedia.com...
                    > Hmm, start by creating an empty dataProvider variable and binding the DG
                    > to that.
                    >
                    > then use the dataProvider API to add items.
                    >
                    > Tracy