6 Replies Latest reply on Nov 28, 2007 9:53 AM by Zolotoj

    SelectedItem

    Zolotoj Level 3
      I am working on a custom DataGrid class that will enter a new row at the scroll down when no more rows are available. This a line of a code that inserts a new row:
      this.dataProvider.addItem(this.selectedItem)
      What that will do is to insert a duplicate of a last row into a new row. But what I want is to blank out this.selectedItem first to insert blank values. I can idex this.selectedItem like this:
      this.selectedItem[0][0] , this.selectedItem[0][1] , this.selectedItem[0][2] , and so forth but that is a generic solution. Instead I would want to do something like this:
      this.selectedItem[0]["column_dataField_name"] which will make the code generic. So, a few questions:
      1. How to get column_dataField_name for a specified column?
      2. How to blank out this.selectedItem items to provide empty values for a new row?

      Thanks

        • 1. Re: SelectedItem
          ntsiii Level 3
          DataGrid.columns returns a copy of the array of DataGridColumn references. So myDG.columns[0].dataField; would return the string specified in the dataField property for that column. You can iterate over this array.

          It will be difficult to do this totally generically, because the dataProvider items can be almost any kind of object, like complex xml or a dynamic object, or a strongly typed VO, or an Array, a collection, or just a simple value.

          If you can restrict your use-cases, it will help.

          Tracy
          • 2. Re: SelectedItem
            Zolotoj Level 3
            For that kind of datagrid I am going to use a simple XML data looks something like this:
            <data>
            <customer firstname="first name" lastname="last name" />
            </data>
            No complex data objects.
            • 3. Re: SelectedItem
              ntsiii Level 3
              Ok, that is much simpler.

              var xmlNew:XML = XML(myDG.selectedItem).copy();
              var xlAttrubutes:XMLList = xmlNew.attributes; //and xmllist of attributes
              for (var i:int=0;i<xlAttributes.length;i++) {
              xlAttributes [ i ] = ""
              }

              You will want to see the docs for the exact syntax, but the above is close.

              Tracy
              • 4. SelectedItem
                Zolotoj Level 3
                xmlNew.attributes gives me an error. I am trying to apply any XML related method/property to xmlNew but nothing works. Is it really an xml document?
                BTW, here is a sample of it:
                <tforce>
                <id>
                31
                </id>
                <name>
                Zachary F. Ziobro
                </name>
                <occupation>
                Utility Carmen
                </occupation>
                <company>
                BRC
                </company>
                <worknum>
                6669
                </worknum>
                <department>
                Car Department
                </department>
                <hphone>
                630-257-7291
                </hphone>
                <wphone/>
                </tforce>
                • 5. Re: SelectedItem
                  ntsiii Level 3
                  Syntax error. See the docs.
                  Tracy
                  • 6. Re: SelectedItem
                    Zolotoj Level 3
                    Actual code is
                    var xmlNew:XML = XML(this.selectedItem).copy();
                    var xlAttrubutes:XMLList = xmlNew.attributes();

                    Run-time Error:
                    TypeError: Error #1010: A term is undefined and has no properties.
                    at CustomComponents::ListGridEditable/KeyDown()[D:\testarea\beltrailway\flexversions\src\Cus tomComponents\ListGridEditable.as:22]