Skip navigation
Currently Being Moderated

Strange Behaviour on DataGrid with ArrayCollection as DataProvider

Nov 11, 2011 3:10 AM

Tags: #flex #actionscript_3 #dataprovider #arraycollection

I have a Datagrid with an ArrayCollection as DataProvider, the arrayCollection is partially generated by a remoteObject call, the dataprovider seems to works at least until I try to edit the field...



By the RemoteObject I only receive an ArrayCollection with the field `ip`, but the datagrid looks for the fields ip, check and save...

If I add/edit this new field it works, but only under particular condition





The DataGrid:



 <s:DataGrid id="datagrid" left="10" right="10" top="136" 
       dataProvider="{listaIPCheck}" bottom="10" requestedRowCount="4">
                     <s:GridColumn dataField="ip" headerText="Asset"/>
                     <s:GridColumn dataField="check" headerText="Inventory"/>
                     <s:GridColumn dataField="save" headerText="Salvataggio"/>


The Script:




   [Bindable]private var listaIPCheck:ArrayCollection; 
    private function ro_resultHandler(event:Event=null):void
      listaIPCheck = new ArrayCollection();
      listaIPCheck = ro.getListUpdate.lastResult;
      heap = 0; 
      // Read Below {POINT #1}
    private function init3():void
     // Read Below {POINT #2}
     if (heap<listaIPCheck.length)
        // omitted the initialization of the process p
        p.addEventListener(NativeProcessExitEvent.EXIT, onExit);
    private function onExit(e:NativeProcessExitEvent):void { 
        // Read below {POINT #3}

Here is my code, now as you can see there are 3 line where I wrote to read below...

Let's assume to put this simple `for` instead of the commented line (once at a time)



    for (var k:Number=0;k<listaIPCheck.length;k++)
      listaIPCheck.getItemAt(k).check = "checkVal";
      listaIPCheck.getItemAt(k).save = "saveVal";


This code always work in the 3 points, so at the end of the call the ArrayCollection is always filled with the new values, but the datagrid refresh the items only in POINT #1 and POINT #2

Why not in Point #3???

  • Currently Being Moderated
    Nov 11, 2011 5:28 AM   in reply to Z4g0s

    I don't actually see your points 1, 2, and 3.


    However, let me offer this suggestion: just add the missing properties to the php Class (or whatever your remote object is pointing to) definition.  When the objects get instantiated on the PHP side, they will then have the properties you need.

    Mark as:
  • Currently Being Moderated
    Nov 11, 2011 6:23 AM   in reply to Z4g0s

    Try calling itemUpdated for every item in your AC when you update it in the for loop.

    Mark as:
  • Currently Being Moderated
    Nov 11, 2011 7:04 AM   in reply to Z4g0s

    When you get a lot of elements in your list, you'll probably also find it resets the selectedIndex and jumps to the first row of data.  It doesn't update automatically because ArrayCollection doesn't listen to the objects inside it to see if they are changing.  When they change, you need to tell the ArrayCollection they changed, by calling itemUpdated.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points