2 Replies Latest reply on Feb 12, 2010 10:11 AM by iamiqbal

    Populate data grid with java collection

    iamiqbal

      Hello:

       

      I am trying to populate data grid with return value obtained from java method invocation.

       

      Java method returns collection of java data objects.

       

      When i debug i can see that collection of objects are available in flex resultevent.

      How to set this into my datagrid.

       

      [Bindable]

       

      private var dataVar:ArrayCollection;

       

       

       

      private function displayList(evt:ResultEvent):void {

       

      dataVar = evt.result;  // This line is showing compile error

      calcTime();

      }

       

      <mx:DataGrid

       

      id="data" dataProvider="{dataVar}"/>

       

      Also if anyone can let me know how to populate data grid dynamically. I mean the number of columns and rows are not known

      until i run the application. When i run the application and click on button it gets columns / rows and populates data grid.

       

      Appreciate any inputs on this.

       

      Thanks,

      Iqbal.M

        • 1. Re: Populate data grid with java collection
          yoav@cyteam.com

          If your dataVar  is assigned as the  dataProvider for your DataGrid  then you can:

           

          In your result handler either:

          1.)  Process the the result.data  array item by item and add them using dataVar.addItem()

          for this you will need to initially allocation a  new ArrayCollection   ( e.g. dataVar = new ArrayCollection() )

           

          2.)  If you are certain that the result.data has the proper structure you can use it in the ArrayCollection constructor

          var itemsArray:Array = result.data as  Array;

          dataVar = new ArrayCollection(itemsArray);

          • 2. Re: Populate data grid with java collection
            iamiqbal Level 1

             

             

            I got it working.

            This is how i have achieved.

            Thanks for the reply.

             

            [

            Bindable]

             

            private var dataVar:ArrayCollection;

             

             

            private function displayList(evt:ResultEvent):void {

             

            var len:int = evt.result.length;

            textField.text+=len;

             

            var tempData:ArrayCollection = new ArrayCollection();

            dataVar =

            new ArrayCollection();

             

             

             

            for(var i:int=0;i<len;i++)

            {

             

            dataVar.addItem(evt.result[i]);

            }

            }

             

             

            <mx:DataGrid id="data" dataProvider="{dataVar}"/>