Hikari
Hikari

Reputation: 3947

Capture page number in Ext.PagingToolbar

I'm working on a ExtJS.Grid that uses a Ext.data.Store with jsonp proxy and Ext.PagingToolbar to control paging. It's all working fine.

But some users are complaining that they further browse pages, leave the grid, and when they come back they are back to page 1. They want "the grid to remember" the page they were and starts on it.

I use a Ext.onReady(function(){},false); to define all components and another Ext.onReady(function(){}); to create the grid with a store.loadPage(1); to make the first load after everything is done.

If I could listen to some event from the Ext.PagingToolbar, when a new load happens, and capture the page it was used, I could pehaps store it in some cookie or something, and retrieve it to load that page again.

I looked on http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.toolbar.Paging and found no event that could be used. Anybody has any idea of where I could do it?

Upvotes: 0

Views: 843

Answers (1)

Bojan Dević
Bojan Dević

Reputation: 1875

You can track the change event of the Ext.toolbar.Paging and remember the currentPage in a cookie.

pagingtoolbar.on('change', function(pb, pageData) {
  Ext.util.Cookies.set('lastGridPage', pageData.currentPage, new Date('1/1/2016'));
});

And setup your grid to load that page on afterrender

grid.on('afterrender', function() {
  var pageNumber = Ext.util.Cookies.get('lastGridPage') || 1;
  grid.store.loadPage(pageNumber);
})

Upvotes: 1

Related Questions