PDA

View Full Version : store.reload is not working



sampada
28 May 2009, 1:35 AM
Hi

I have added a search function in datagrid toolbar. I can pass the data to the backend (whatever typed in search field)and obtained result from server successfully . I then have relaod the grid with the data returned from server. But I am not able to get results with store.reload


I have posted some code snippets here: Any ideas where I went wrong
Ext.onReady(function(){


var reader=new Ext.data.JsonReader(
{
......
},
)

var store=new Ext.data.Store( {
proxy:proxy,
reader:reader
});

store.load();

var grid = new Ext.grid.GridPanel({

......
tbar:[{

'Search By', ' ',
{
xtype:'trigger',
id:'txtSearch',
width:250,
fieldLabel:'search',
emptyText: 'Item Name',
triggerClass:'x-form-search-trigger',
listeners: {specialkey: function(f, e){if(e.getKey() == e.ENTER){performSearch(this.getRawValue())}}},
onTriggerClick:function(){performSearch(this.getRawValue());}
}

]}


In performsearch function

function performSearch(searchTerm){
// alert(searchTerm);

//searchTerm contains the name to be searched -- filter in server side

Ext.Ajax.request({
url : '/4DACTION/json_search' ,
params : { name : searchTerm},
method: 'POST',
success: function ( result, request ) {
Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);

},
failure: function ( result, request) {
Ext.MessageBox.alert('Failed', result.responseText);
}
});

store.reload();// not working
}

pbeforeswine
28 May 2009, 4:24 AM
Ajax Requests are A-synchronous. Therefore, your reload call must be when success is called. Like so...


Ext.Ajax.request({
url : '/4DACTION/json_search' ,
params : { name : searchTerm},
method: 'POST',
success: function ( result, request ) {
Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
store.reload();//reload will be called, when AJAX call is successful.
},
failure: function ( result, request) {
Ext.MessageBox.alert('Failed', result.responseText);
}
});

sampada
28 May 2009, 4:36 AM
Hi, thanks for the response. I have tried that one but still not able to reload the grid. The message pops up with correct data in success function but store is not reloaded

pbeforeswine
28 May 2009, 4:54 AM
This exact same setup that I have for my project works beautifully.

Maybe, the data in the grid is very large, have to tried waiting sometime before checking if it is reloaded? In your grid, try setting the property "loadMask" to "true". This will put a "Please wait..." mask over your grid when it loads.

Finally, can you check if the data is really saved to the Database or whatever?

sampada
28 May 2009, 8:16 PM
Hi ,
if i set loadmask to true, I get message as Loading....
but no difference.

I think the data is saved to database because in result.responseText I get the required data returned from server.

naxito
29 May 2009, 5:04 AM
you have to set up your proxy configuration with search params on perform search and then, call to store.load().

You dont need to specify the Ajax.request, because it is done by store.load() with the configuration of store.proxy.

sampada
1 Jun 2009, 11:31 PM
Hi

how can i setup params in proxy configuration ,I have just tried this one:


function performsearch(searchTerm)

{


var proxy=new Ext.data.HttpProxy({url:'/4DACTION/jsonsearch/'+searchTerm})

var reader=new Ext.data.JsonReader({....})

store.load(); // or I also tried store.load({params:{items:searchTerm}})
}


can i know how i can setup proxy with search params

Animal
1 Jun 2009, 11:39 PM
Pass the params in the load call.

sampada
1 Jun 2009, 11:52 PM
yeah, i set up params in load call as:

store.load({params:{itemname:searchTerm}})
It invokes the method jsonsearch and passes the parameter typed in search field and I get correct data returned also. But store is not reloading yet

walta
10 Jun 2009, 10:18 PM
I have a similar problem right now. I have a bit that uses an ajax request to update some data. In the success callback I log the success (firebug console) and call reload on the store.

The success is logged but the reload seems to never occur. Firebug console does not show a request being made for the reload.

Still trying to figure it out.

Oddly enough, if I execute the exact same reload statement in the firebug console, it works.

walta
10 Jun 2009, 10:23 PM
Solved my issue. Failed to remember that the success call is in a different scope. My reference to this was not the correct one so behaviour was wonky. Corrected the reference and it works.

It's possible your code has a scope issue hiding in there somewhere.

sampada
11 Jun 2009, 10:33 PM
Solved my issue. Failed to remember that the success call is in a different scope. My reference to this was not the correct one so behaviour was wonky. Corrected the reference and it works.

It's possible your code has a scope issue hiding in there somewhere.

I will check this out