2 Replies Latest reply on Sep 22, 2011 12:15 AM by CoolCatToM

    Problem with datagrid dataprovider

    CoolCatToM

      I'm wondering why is it my search result is null after I press search button. After I press search, the datagrid is blank. But I ever test my service and it's working.

      Anyone has any idea how to solve it? So sorry I'm totally new to FLEX... >.<

      Below is my code...

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                             xmlns:s="library://ns.adobe.com/flex/spark"

                             xmlns:mx="library://ns.adobe.com/flex/mx"

                             xmlns:productbasicservice="services.productbasicservice.*"

                             width="1024" height="768">

          <fx:Script>

              <![CDATA[

                  import mx.collections.ArrayCollection;

                  import mx.controls.Alert;

                  import mx.controls.TextInput;

                  import mx.events.DataGridEvent;

                  import mx.events.FlexEvent;

                  import mx.rpc.AsyncToken;

                 

                  import valueObjects.Product_basic;

                 

                  protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

                  {

                      getProduct_basic_pagedResult.token = productbasicService.getProduct_basic_paged();

       

                  }

                  protected function saveClick(event:MouseEvent):void

                  {

                      productbasicService.commit();

                  }

                 

                  protected function revertData(event:MouseEvent):void

                  {

                      productbasicService.revertChanges();

                  }

                 

                 

                  protected function searchData(event:MouseEvent):void

                  {

                      var searchStr:String = searchbox.toString();

                     

                      searchProduct_basicResult.token = productbasicService.searchProduct_basic(searchStr);

                      dataGrid.dataProvider = searchProduct_basicResult.lastResult;

                  }

                 

              ]]>

          </fx:Script>

          <fx:Declarations>

              <s:CallResponder id="getAllProduct_basicResult"/>

              <productbasicservice:ProductbasicService id="productbasicService"

                                                       fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"

                                                       showBusyCursor="true"/>

              <s:CallResponder id="getProduct_basic_pagedResult"/>

              <s:CallResponder id="searchProduct_basicResult"/>

              <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <mx:DataGrid id="dataGrid" x="11" y="61" width="1003" height="557"

                       creationComplete="dataGrid_creationCompleteHandler(event)"

                       dataProvider="{getProduct_basic_pagedResult.lastResult as ArrayCollection}" editable="true">

              <mx:columns>

                  <mx:DataGridColumn width="200" dataField="id" editable="false" headerText="ID"/>

                  <mx:DataGridColumn dataField="name" headerText="name"/>

                  <mx:DataGridColumn width="200" dataField="price" headerText="Price"/>

                  <mx:DataGridColumn dataField="description" headerText="description"/>

              </mx:columns>

          </mx:DataGrid>

          <s:Button x="849" y="22" label="Save" click="saveClick(event)"/>

          <s:Button x="944" y="22" label="Revert" click="revertData(event)"/>

          <s:TextInput x="14" y="22" width="367" id="searchbox"/>

          <s:Button id="button" x="389" y="22" label="Search" click="searchData(event)"/>

      </s:WindowedApplication>

       

      I have added my own data service operation in the php file called searchProduct_basic(searchStr). Basically this function return the object of the search result.

        • 1. Re: Problem with datagrid dataprovider
          Flex harUI Adobe Employee

          Maybe lastResult isn’t an ArrayCollection.  Check your resultFormat setting.

          • 2. Re: Problem with datagrid dataprovider
            CoolCatToM Level 1

            It's the same for lastResult as ArrayCollection.

                        protected function searchData(event:MouseEvent):void

                        {

                            var searchStr:String = searchbox.toString();

                           

                            searchProduct_basicResult.token = productbasicService.searchProduct_basic(searchStr);

                            dataGrid.dataProvider = searchProduct_basicResult.lastResult;

                        }

            For you information, the searchProduct_basic(searchStr) would return Product_basic object. >.<