8 Replies Latest reply on Jul 12, 2007 2:14 PM by deKolonel

    Datagrid Refresh

    texas_stingray Level 1
      I have a datagrid whos dataprovider is the result from a HTTPService it populates correctly and looks great, However I have a combobox that is used to change the dataField. How can I tell the datagrid to refresh/reload so that it will display the values from the new dataField>
        • 1. Re: Datagrid Refresh
          peterent Level 2
          You can either reset the DataGrid's dataProvider to the new object containing the new values, or if you are just re-populating an existing dataProvider Collection, make sure to use the Collection's itemUpdated function. If you are changing a lot of the values, disable the update notification until the end:

          collection.disableAutoUpdate();
          ...
          collection.enableAutoUpdate();
          collection.refresh();

          That will tell all interested parties the data has been changed.
          • 2. Re: Datagrid Refresh
            texas_stingray Level 1
            Let me rephrase the issues. the screen is not refreshing on the datagrid unless I scroll up and down how can I force the screen refresh.
            • 3. Re: Datagrid Refresh
              ntsiii Level 3
              What is your dataProvider, and how are you updating it?
              Tracy
              • 4. Re: Datagrid Refresh
                texas_stingray Level 1
                DataGrid Code Below

                <mx:DataGrid id="TotalsDataGrid" click="TotalVolumeClick(event)" dataProvider="{HTTPServVolume.lastResult.month}" visible="true" left="0" right="0" bottom="30" top="0">
                <mx:columns>
                <mx:DataGridColumn headerText="Date" dataField="date"/>
                <mx:DataGridColumn id="TotalsDGVolume" headerText="Total Volume" dataField="oil"/>
                </mx:columns>
                </mx:DataGrid>

                HTTP Service Below:
                <mx:HTTPService id="HTTPServVolume" url="totalvolume.xml" method="POST" resultFormat="e4x" useProxy="false" showBusyCursor="true" result="HTTPVolumeResults()" fault="HTTPServFault(event);"/>

                totalvolume.xml Below:
                <months>
                <month>
                <date>Jan-04</date>
                <oil>786921</oil>
                <gas>128943</gas>
                <water>5000</water>
                </month>
                <month>
                <date>Feb-04</date>
                <oil>765913</oil>
                <gas>197653</gas>
                <water>5120</water>
                </month>
                <month>
                <date>Mar-04</date>
                <oil>650981</oil>
                <gas>152870</gas>
                <water>4987</water>
                </month>
                <month>
                <date>Apr-04</date>
                <oil>734209</oil>
                <gas>102356</gas>
                <water>5934</water>
                </month>
                <month>
                <date>May-04</date>
                <oil>890253</oil>
                <gas>199367</gas>
                <water>5328</water>
                </month>
                <month>
                <date>Jun-04</date>
                <oil>679023</oil>
                <gas>121078</gas>
                <water>4387</water>
                </month>
                <month>
                <date>Jul-04</date>
                <oil>700568</oil>
                <gas>142561</gas>
                <water>6237</water>
                </month>
                <month>
                <date>Aug-04</date>
                <oil>721890</oil>
                <gas>387941</gas>
                <water>5520</water>
                </month>
                <month>
                <date>Sept-04</date>
                <oil>734477</oil>
                <gas>138760</gas>
                <water>3465</water>
                </month>
                <month>
                <date>Oct-04</date>
                <oil>749809</oil>
                <gas>276451</gas>
                <water>5507</water>
                </month>
                <month>
                <date>Nov-04</date>
                <oil>894629</oil>
                <gas>189078</gas>
                <water>5075</water>
                </month>
                <month>
                <date>Dec-04</date>
                <oil>789045</oil>
                <gas>169549</gas>
                <water>7500</water>
                </month>
                </months>

                Switching dataField Below:
                if(.....)
                TotalsDGVolume.dataField=oil;
                ....
                TotalsDGVolume.dataField=gas;
                ....
                TotalsDGVolume.dataField=water;




                • 6. Re: Datagrid Refresh
                  ntsiii Level 3
                  Ah, nice try, but there are a couple problems.

                  First, you can't refer to a dataGridColumn by id, it has no such property. You can access it using the dataGrid.columns array, and you will be able to set the dataField through that reference.

                  This is essentially rebuilding the DataGrid dynamically. Here is a link to an example that builds a datagrid dynamically. It will help you understand the theory:
                  http://www.cflex.net/showFileDetails.cfm?ObjectID=552

                  Now, to make this all work, you will have to change the way you are assigning the dataProvider to the datagrid, because you will have to re-assign it after modifying the columns.

                  First, don't bind directly to lastResult. Instead, create an instance variable typed as XML: private var _xmlTotalVolume:XML;

                  Pass the event to the result handler:
                  result="HTTPVolumeResults(event)"

                  Import the result event:
                  import mx.rpc.events.ResultEvent;

                  In the result handler do:
                  private function HTTPVolumeResults(event:ResultEvent)
                  _xmlTotalVolume = XML(event.result);
                  TotalsDataGrid.dataProvider = _xmlTotalVolume;

                  Your DataGrid should display normally.

                  Now, after you modify the columns array, you will aggain assign the dataProvider:
                  TotalsDataGrid.dataProvider = _xmlTotalVolume;

                  Another way to achieve this effect would be to programatically hide and display the three columns as desired. You still must use the columns array techniques.

                  Tracy
                  • 7. Re: Datagrid Refresh
                    texas_stingray Level 1
                    Actualy there is an id for the DataGridColumn and it does work. I saw another post and got wat i wanted just by resetting the datagrid dataProvider after I change to DataGridColumn.dataField

                    • 8. Re: Datagrid Refresh
                      deKolonel Level 1
                      Hi,

                      what I did was just create a updateGrid fuction that runs when clicking a button to say add or delete a row.

                      like this:

                      public function updateGrid():void {
                      initApp(); //Make sure this initiate the filling of the datagrid!!
                      }

                      <mx:Button id="addRow" click="this.updateGrid();"