2

Help me please...

I've a simple DataGrid, the dataprovider is a service "getServiceDatiResult.lastResult", this service is from webmethod aspnet that return a sqlserver data. I created Event by click_button that insert data and get data into Datagrid.... The problem is the datagrid. It refresh data only when i call button event several times..

I ve tryed :

datagrid.refresh();

datagrid1.columns.clear();
datagrid1.columns.refresh();

getServiceDatiResult.lastResult.refresh();
getServiceDatiResult.lastResult.commit();

the code:

<mx:DataGrid id="datagrid1" creationComplete="datagrid1_creationCompleteHandler(event)"
             dataProvider="{getServiceDatiResult.lastResult}" dropShadowVisible="true"
             fontSize="12" fontWeight="normal" textAlign="center" verticalAlign="middle" editable="true">

<s:Button id="button3"  label="Insdata3_now" click="button3_clickHandler(event)"/>


[Bindable]
protected function button3_clickHandler(event:MouseEvent):void
{
    getServiceDatiResult.token = service.getServiceDati();

        <!-- regresh ???? -->           
    getServiceDatiResult.lastResult.commit();
    getServiceDatiResult.lastResult.refresh();
}
Raja Jaganathan
  • 33,099
  • 4
  • 30
  • 33
FabCodes
  • 23
  • 1
  • 5
  • it seems to be lot problem so post your service call code and what will be return type of your webmethod(xml,array,json). – Raja Jaganathan Jan 31 '14 at 12:13
  • @RajaJaganathan I don't thinkt he service call code matters here; especially since he isn't processing the results in any way. The dataProvider is `getServiceDatiResult.lastResult` . However, knowing the type of data returned would be helpful; probably not JSON b/c the Flex MX DataGrid wouldn't know what to do with it. – JeffryHouser Jan 31 '14 at 14:46
  • @Reboog711 my point in service call place we need to assign to Arraycollection with getServiceDatiResult.lastResult so that it get updated automatcially.so we can solve problem quick anyhow.np – Raja Jaganathan Jan 31 '14 at 18:51
  • How i can assign getServiceDatiResult.lastResult to Arraycollection?? – FabCodes Feb 01 '14 at 17:21

5 Answers5

8

You want to refresh the DataGrid's dataprovider; which in turn will update the DataGrid.

Assuming you have an ArrayCollection, you can use the refresh() method to refresh all items:

(datagrid.dataProvider as ArrayCollection).refresh();

If you are only refreshing a single item, you can save some processing time by updating a single item with itemUpdated():

(datagrid.dataProvider as ArrayCollection).itemUpdated(item);

The MX DataGrid will take any object and try to display it in the DataGrid, so if you're getting an Array or XML returned from the server, you may have to replace the dataProvider:

datagrid.dataProvider = newDataProvider;
JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Is your dataProvider an ArrayCollection? – JeffryHouser Feb 01 '14 at 18:43
  • I just want to note, just by the way, that there is always better to use casting then the "AS" operator. coz now you are hiding possible error behind another - Just imagine that dataProvider is not ArrayCollection. If you cast to arraycolelction you will get nice error: "cannot cast XXX to ArrayCollection. But in your case as you wrote it, you will get "acces to null arror", which does not say you anything and after some digging later you will find out that you have incorrect type then you expected... – user3190916 Feb 02 '14 at 13:20
  • @user3190916 The 'as' operator is a way to cast something. – JeffryHouser Feb 02 '14 at 15:08
  • Also check out this answer to another question about casting performance: http://stackoverflow.com/a/14268394/133840 – JeffryHouser Feb 02 '14 at 15:10
0

I agree with Reboogs solution. Another way of doing it is do, dataGrid.invalidatelist(), this is little heavy when compared to that of the dataprovider.refresh() as invalidation will reload and repaint the UI.

Zeus
  • 6,386
  • 6
  • 54
  • 89
0

I think if you write this request calling correctly, refresh is not needed at all! For me, it looks like you are calling some async request, but maybe you asume its synchronous operation. I think is because of the [Bindable] tag at the handler method, why do you have it there?

But to decide I think you did not give us all information. For example - where is set variable getServiceDatiResult? you set some token inside, but what and where is set the lastResult?

I repeat I think just to call simple request, there is no need to refresh anything, the problem is elsewhere - handling the request itsef.

user3190916
  • 737
  • 8
  • 8
0

the (datagrid.dataProvider as ArrayCollection).refresh(); method is valid when you use Array like dataprovider ... In my case the problem is that click button(event) call 3 service that get update 3 different datagrid... So I 've 3 callresponder on 3 select to SqlServer by aspNet ... sincronize all operation is to much... my temporaney personal solution is modified Sql Table and reduce operation with click button(event) .. on this way datagrid update perfectly ... but i'm study a new solution ..thank you for help...

FabCodes
  • 23
  • 1
  • 5
0

Just Refresh your data provider as follow,

var datapro:ArrayCollection = new ArrayCollection();
//

function dataRefresh():void
{
  datapro.refresh();
}

//
//
<mx:DataGrid id="datagrid1"  creationComplete="datagrid1_creationCompleteHandler(event)" dataProvider="{datapro}">
//
//
Kans
  • 13
  • 2