PDA

View Full Version : How to refresh a List after AJAX call was successful?



PHANTOMIAS
24 Oct 2011, 4:07 AM
Hello!


I have a MVC Sencha Touch application. In one screen I have a list and segmented buttons.
Pressing a button, this is called:


Ext.dispatch({
controller: project.controllers.aController,
action: 'show',
id: segmentedButton.getId()
});

The show function of the "aController":


show: function(options) {
var id = options.id;
project.stores.a.proxy.extraParams = { test: id };
project.stores.a.load();
project.views.viewport.setActiveItem(project.views.a, options.animation);
}

And this is the store:


project.stores.a = new Ext.data.Store({
model: "project.models.A",
proxy: {
type: 'ajax',
url: ' http://www.sometests.com/',
reader: {
type: 'json'
}
},
autoLoad:true
});

And now I have the problem which is described here:
http://www.movableapp.com/2011/09/sencha-touch-list-scroll-to/

If I have a list with many entries, scroll to the bottom and then change to a list
with only a few list entries, I do not see any list entry.

So I want to perform these two lines after the AJAX call successfully finished:


List.doComponentLayout();
List.refresh();

The list (in items section) is in the same Panel as the segmented buttons (in dockedItems section).

How can I perform these two lines after the AJAX call is finished successfully in my scenario?

Best Regards.

PHANTOMIAS
24 Oct 2011, 5:23 AM
I can use this in my Ext.data.store:

project.stores.a = new Ext.data.Store({
model: "project.models.A",
proxy: {
type: 'ajax',
url: ' http://www.sometests.com/',
reader: {
type: 'json'
},
afterRequest: function (request, success) {
if (success) {
console.log("afterrequest - success");
// How can I here perform actions on the list?
}
}
}
});

With afterRequest and the check if it was successful, this could be the place where to perform the "doComponentLayout" on my List. But how can I call the function of the list inside afterRequest? Or can I call a custom function which I can write into my List?

Best Regards.

mitchellsimoens
24 Oct 2011, 8:33 AM
Ext.List should be putting listeners onto the Store to fire off the refresh method on the Ext.List automatically.

PHANTOMIAS
24 Oct 2011, 8:50 AM
Thanks for your reply. Puh, can you give me some examples how to do this?

I solved it by calling a custom function in the afterRequest function. It works, but not a nice solution...