0 Replies Latest reply on Jan 13, 2007 8:42 AM by swickes

    Datagrid not refreshing after drag and drop

    swickes Level 1
      Please help me solve this: my datagrid DOES refresh itself, but only after the SECOND drag and drop.

      Here's an example of my datagrid :
      1. Label a Description a
      2. Label b Description b
      3. Label c Description c

      When I drag the third row to the top of the datagrid, I want to see updated row numbers like this:
      1. Label c Description c
      2. Label a Description a
      3. Label b Description b

      But I see this
      3. Label c Description c
      1. Label a Description a
      2. Label b Description b

      Now let's swap rows 2 and 3; now the datagrid will correctly show 1. in the first row! (Of course 3. and 2 are messed up until the next drag and drop).
      1. Label c Description c
      2. Label b Description b
      1. Label a Description a

      As you can see, row #1 is now correctly displaying "1." This is happening only after the second drag and drop occurs.

      Here's my strategy:
      1. I'm using a datagrid with an ArrayCollection as the dataprovider.
      2. The datagrid uses the dragComplete event to call a function (function shown below).
      3. This function uses a loop to update the property GOALORDER of each row in the ArrayCollection
      4. This function also creates an object of new GOALORDER's to update the database (this part is working fine).

      I've noticed somewhere in the docs that, when a datagrid is experiencing multiple changes it turns on ArrayCollection.disableAutoUpdate automatically. IS THIS TRUE? This could explain why my datagrid does not immediately refresh.

      Is there some way to drag and drop, update the ArrayCollection, and refresh the datagrid- in that order?


      Here's the misbehaving function!

      // re-sort the list NOTE first index=0, first goalorder=1
      private function reSort():void
      var params:Object = new Object();
      params.DBACTION = "reorder";
      var i:int;
      var g:int;

      for (i = 0; i < acGoals.length; i++)
      // replace GOALORDER in ArrayCollection
      var editRow:Object = acGoals ;
      editRow.GOALORDER = g;
      acGoals.setItemAt(editRow, i);
      // create multiple entries to edit database
      params["GOALID"+g]= acGoals.getItemAt(i).GOALID;
      params["GOALORDER"+g]= g;
      params["rowsToUpdate"] = g;

      //HTTPService to