7 Replies Latest reply on Oct 17, 2010 10:53 PM by Flex harUI

    Editing a Datagrid

    leonapster

      i have a datagrid component and i want to edit it inline.

      I used the itemEditEnd event of my grid but my application go to "loop".

      And how i get the new edited value? Can i get also the name of another column of my selectedItem (for example id, but no ID of datagrid item, id from my database)

       

       

       

       

      protected function dataGrid_itemEditEndHandler(event:DataGridEvent):void
      {
                      Alert.show('edited');
      }

       

       

      <mx:DataGrid id="dataGrid"
                       dataProvider="{arrColl}"
                       editable="true"
                       itemEditEnd="dataGrid_itemEditEndHandler(event)"
                       rowCount="8">
              <mx:columns>
                  <mx:DataGridColumn dataField="label"
                                     editable="false" />
                  <mx:DataGridColumn dataField="score"
                                     editable="true" />
              </mx:columns>
          </mx:DataGrid>

        • 1. Re: Editing a Datagrid
          Devtron Level 3

          You will need to have a column in your DataGrid for the "ID" database  field. You can set it to visible=false to hide it, but can still  reference the ID value.

           

           

          <mx:DataGridColumn dataField="id"  id="myIDColumn" editable="false" visible="false" />

           

          You can reference the column like so:

          dataGrid.myIDColumn.text;

           

          I would rename your datagrid to something other than "datagrid". Name it "dg" or something, just so you dont run into naming/reference problems.

          • 2. Re: Editing a Datagrid
            leonapster Level 1

            Ok, but have i to use  itemEditEnd event?

             

            I tried but return me this error:

             

            1119: Access of possibly undefined property myIDColumn through a reference with static type mx.controls:DataGrid.    line 26    Flex Problem

             

             

             

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                           >
                <fx:Declarations>
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
                   
                    <s:ArrayCollection id="arrColl">
                       
                        <fx:Object  myID="85" />
                        <fx:Object  myID="88" />
                       
                    </s:ArrayCollection>
                   
                </fx:Declarations>
               
                <fx:Script>
                    <![CDATA[
                        import mx.controls.Alert;
                        import mx.events.DataGridEvent;

             

                       
                        protected function dataGrid_itemEditEndHandler(event:DataGridEvent):void
                        {
                            Alert.show(dg.myIDColumn.text);
                           
                        }

             

                    ]]>
                </fx:Script>

             

               
                <mx:DataGrid id="dg"
                             dataProvider="{arrColl}"
                             editable="true"
                             itemEditEnd="dataGrid_itemEditEndHandler(event)"
                             rowCount="8">
                    <mx:columns>
                        <mx:DataGridColumn dataField="myID"  id="myIDColumn" editable="true" visible="true" />
                       
                       
                    </mx:columns>
                </mx:DataGrid>

             

               
            </s:Application>

            • 3. Re: Editing a Datagrid
              leonapster Level 1

              how hands the new edited value of my datagrid?

              • 4. Re: Editing a Datagrid
                leonapster Level 1

                up

                • 5. Re: Editing a Datagrid
                  Flex harUI Adobe Employee

                  Using Alert in ITEM_EDIT_END is not recommended.  You can delay the Alert

                  with callLater, but better to find a different way.

                  • 6. Re: Editing a Datagrid
                    leonapster Level 1

                    for example?

                    • 7. Re: Editing a Datagrid
                      Flex harUI Adobe Employee

                      If you are debugging, I would use trace statements or a separate TextArea.

                      If you are doing validation, just set the editedItemPosition back to the

                      cell that is invalid and maybe set the errorTip on the editor.