View Full Version : Paging toolbar grid - Adding Records

24 Feb 2011, 3:19 AM
Hi there,

I have a grid that I'm using to do some CRUD on a list of users. I needed to add a paging toolbar for this as I'll potentially have a huge number of users. I've also configured the store on the grid to work with an HTTPProxy so that it will make all the Ajax requests for me and I persist them to my database immediately.

The problem I'm having is that when I add a record to the grid, my paging toolbar and number of results per page is thrown off. What I did to fix this was that whenever I Create, Edit, Update or Delete a user, I call the doRefresh() function on the paging toolbar to make sure that everything is kept in sync. It's not a brilliant solution but it does the job.

onCreateUser : function(userData) {
var record = new this.store.recordType(userData);

However... this seems to be causing a bit of a race condition for me though. Every now and then, the Ajax request for the toolbars refresh is done BEFORE, the new user is actually persisted to the database. This makes the newly added record "disapear" from the grid completely.

Has anybody had any experience with how to keep the paging toolbar in sync with changes being made to the store? Any suggestions as to what I can do to either fix the race condition I have here or if there are any alternative solutions to this when persisting immediately would be greatly appreciated.



24 Feb 2011, 3:48 AM
You are using a store writer? In that case you would have to wait for the store 'save' event before you can reload.

But do you really need to reload? You could also:

pagingToolbar.onLoad(store, store.data.items, store.lastOptions);
(which is what my PagingStore user extension with extended PagingToolbar already does automatically)

24 Feb 2011, 5:49 AM
Thanks a lot for the example Condor, it did exactly what I wanted it to do and solved a few other problems I was having too :)