1 Reply Latest reply on Oct 31, 2009 4:18 AM by paul.williams

    How to set 2 dataProviders for 1 dataGrid?

    petousas
      <mx:DataGrid x="750" y="365" id="dataGrid2"  dataProvider="{deleteCouponResult.lastResult}" width="240">
                <mx:columns>
                     <mx:DataGridColumn dataField="msg" headerText="message"/>
                </mx:columns>
           </mx:DataGrid>

      The above dataGrid is used as a feedback area where i fill it with message from database operations like

      "Item succesfully inserted", "Can't insert item", "Deletion succesfull"...etc

       

      By this time i can only assign one callResponder to my dataGrid but i want also to these:

                <s:CallResponder id="getAllCouponsResult"/>
                <s:CallResponder id="setCouponResult"/>
                <s:CallResponder id="insertCouponResult" />
      
      

       

      My first thought wat to play with binding through actionscript but the below code worked only in the second time add button clicked

      protected function addButton_clickHandler(event:MouseEvent):void
      {
           dataGrid2.dataProvider = insertCouponResult.lastResult;
           insertCouponResult.token = couponsController.insertCouponAction(coupon);
           refresh();
      }
      
      

       

      thanks you very much

      Using Flash Builder 4beta2 with flex 4

        • 1. Re: How to set 2 dataProviders for 1 dataGrid?
          paul.williams Level 4

          Create a private variable in your component:

           

          [Bindable]

          private var gridData : ArrayCollection; // or whatever dataprovider type you are using

           

          Then set this property in the result event handler of each CallResponder, eg:

           

          <s:CallResponder
              id="getAllCouponsResult"
              result="gridData = ArrayCollection( event.result )"/>

           

          Then bind your grid's dataProvider to this private variable:

           

          dataProvider="{gridData}