13 Replies Latest reply on Nov 29, 2007 4:02 AM by Sreenivas R

    drag to DataGrid

    KironeX
      Is it possible to do an insert action into the database when drag is complete

      I have a dataGrid that holds the original data and want to drag this data into a new datagrid the moment the drag is complete it should be inserted into the database and then the usual edits can be done to the data (the last part i have working)
        • 1. Re: drag to DataGrid
          atta707 Level 2
          Yes. Absolutely possible.

          Is your first datagrid already writing to DB? If so that's exactly how the second one write it to DB once drag and drop is complete; using dragDrop event.

          If that's not the case, you need to elaborate a bit more what situation you're in.

          ATTA
          • 2. drag to DataGrid
            KironeX Level 1
            my first is getting it's data from a db and i can edit the fields and it will also store it to db again but i cant figure out how the dragDrop eventcould/should activate the insert record action

            i tried to do it like this but it didnt insert to dataBase

            quote:

            private function insertItem(e:AdvancedDataGridEvent):void {
            var dsRowIndex:int = e.rowIndex;
            var dsFieldName:String = e.dataField;
            var dsColumnIndex:Number = e.columnIndex;

            var vo:* = dataArr[dsRowIndex];

            var col:AdvancedDataGridColumn = dataGrid.columns[dsColumnIndex];
            var newvalue:String = dataGrid.itemEditorInstance[col.editorDataField];

            trace("a:" + dsRowIndex + ", " + dsFieldName + ", " + dsColumnIndex);

            var parameters:* =
            {
            "id": vo.idCol, "naam": vo.naamCol, "aantal": vo.aantalCol, "categorie": vo.categorieCol, "prijs": vo.prijsCol, "searchkey": vo.searchkeyCol }

            parameters[dsFieldName.substr(0,dsFieldName.length-3)] = newvalue;

            doRequest("Insert", parameters, insertItemHandler);
            }
            • 3. Re: drag to DataGrid
              atta707 Level 2
              I'll assume that your data is actually being moved to from DG1 to DG2. Also, I'll assume that you've dragDrop event listener set up on DG2 and it is getting fired when you drag and drop data to it.

              if above expectations are correct, then all you need to do is to call inserItem method passing is the reference of DG2 and it should work.

              You code would look something like this:

              <AdvancedDataGrid id="dg2" dragDrop="handleDragDrop(event)"..../>

              private function handleDragDrop(event:DragEvent) : void {
              insertItem(event.currentTarget);
              OR
              callLater(insertItem, [event.currentTarget]);
              }


              ATTA
              • 4. Re: drag to DataGrid
                KironeX Level 1
                i then get this error in the private function

                Severity and Description
                1118: Implicit coercion of a value with static type Object to a possibly unrelated type mx.events:AdvancedDataGridEvent.

                Path
                inventory_manager/src

                Resource
                sellingScript.as

                Location
                line 83

                Creation Time
                1,19617E+12
                • 5. Re: drag to DataGrid
                  atta707 Level 2
                  try:
                  insertItem(event.currentTarget as AdvancedDataGrid);

                  or

                  insertItem(this.dg2);

                  assuming the dg2 is the id of the second datagrid.

                  ATTA
                  • 6. Re: drag to DataGrid
                    KironeX Level 1
                    i have uploaded the mxml and .as scripts maybe you can find something wrong in the code cause it keeps giving the same error

                    http://www.drazenj.com/flex/sellView.mxml
                    http://www.drazenj.com/flex/sellingScript.as

                    the mxml is running as an custom component

                    • 7. Re: drag to DataGrid
                      atta707 Level 2
                      After drag and drop do you rows moved to datagrid2?

                      what's the error?

                      ATTA
                      • 8. Re: drag to DataGrid
                        KironeX Level 1
                        the rows do get moved to datagrid2 but they dont get inserted into the database the error i get after using the codetips you gave is

                        1067: Implicit coercion of a value of type mx.controls:AdvancedDataGrid to an unrelated type mx.events:AdvancedDataGridEvent.

                        • 9. Re: drag to DataGrid
                          atta707 Level 2
                          change function signature from:

                          private function insertItem(e:AdvancedDataGridEvent):void

                          to

                          private function insertItem(e:AdvancedDataGrid):void

                          and you're good to go!

                          ATTA

                          • 10. Re: drag to DataGrid
                            KironeX Level 1
                            tried it and now the 3 lines below the private function insertItem(e:AdvancedDataGrid):void are giving the following error

                            1119: Access of possibly undefined property columnIndex through a reference with static type mx.controls:AdvancedDataGrid.
                            • 11. Re: drag to DataGrid
                              KironeX Level 1
                              ok nyone please shed some lighti'm almost done with it just this tiny problem
                              • 12. Re: drag to DataGrid
                                atta707 Level 2
                                it's not going to work the way you have your code right now! i'm sorry to say that, but it won't!

                                You need to understand how do you want to rewrite insertItem method. Currently it save every time any column is changed in the data grid.

                                With drag and drop you have a totally different case! don't have a single column edit, but multiple rows with multiple columns!

                                So your code should read each from of the new datagrid and put it in the DB.

                                ATTA
                                • 13. Re: drag to DataGrid
                                  Sreenivas R Adobe Employee
                                  I tried to achieve this by listening to the CollectionEvent.COLLECTION_CHANGE event on the 2nd ADG. And it seems to work.

                                  The sample source is here http://sreenivas.ramaswamy.googlepages.com/DragDropInsert.mxml.

                                  I think this is easier than doing this in dragDrop handler. Do you have any particular reason you want to do it in dragDropHandler?